package com.hgkj.cloud.customer.controller;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.hgkj.cloud.base.common.PageInfo;
import com.hgkj.cloud.base.domain.AdminUser;
import com.hgkj.cloud.base.domain.EUser;
import com.hgkj.cloud.base.domain.ExtPsychologist;
import com.hgkj.cloud.base.domain.TenantFrameworks;
import com.hgkj.cloud.base.domain.TenantLogs;
import com.hgkj.cloud.base.domain.TenantNotices;
import com.hgkj.cloud.base.domain.TenantOrderInfo;
import com.hgkj.cloud.base.domain.TenantOrderPsychologist;
import com.hgkj.cloud.base.domain.TenantOrderRecord;
import com.hgkj.cloud.base.domain.TenantPsychologicalAcvitity;
import com.hgkj.cloud.base.domain.TenantPsychologicalCase;
import com.hgkj.cloud.base.domain.TenantPsychologicalCaseWarningFeedback;
import com.hgkj.cloud.base.domain.TenantPsychologicalCounseling;
import com.hgkj.cloud.base.domain.TenantUsers;
import com.hgkj.cloud.base.service.AdminUserService;
import com.hgkj.cloud.base.service.ExtPsychologistService;
import com.hgkj.cloud.base.service.SysTenantsService;
import com.hgkj.cloud.base.service.TenantFrameworksService;
import com.hgkj.cloud.base.service.TenantLogsService;
import com.hgkj.cloud.base.service.TenantNoticesService;
import com.hgkj.cloud.base.service.TenantOrderInfoService;
import com.hgkj.cloud.base.service.TenantOrderPsychologistService;
import com.hgkj.cloud.base.service.TenantOrderRecordService;
import com.hgkj.cloud.base.service.TenantPsychologicalAcvitityService;
import com.hgkj.cloud.base.service.TenantPsychologicalCaseService;
import com.hgkj.cloud.base.service.TenantPsychologicalCaseWarningFeedbackService;
import com.hgkj.cloud.base.service.TenantPsychologicalCounselingService;
import com.hgkj.cloud.base.service.TenantUsersService;
import com.hgkj.cloud.customer.common.AjaxJson;
import com.hgkj.cloud.customer.common.ResponseData;
import com.hgkj.cloud.customer.util.DateTimeUtil;
import com.hgkj.cloud.customer.util.DateUtil;

import cn.hutool.extra.mail.MailUtil;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

@Controller
@RequestMapping("/order")
public class OrderController extends BaseController {
    private static Log log = LogFactory.getLog(OrderController.class);

    @Autowired
    private TenantOrderRecordService tenantOrderRecordService;
    @Autowired
    private TenantPsychologicalCaseService tenantPsychologicalCaseService;
    @Autowired
    private TenantPsychologicalAcvitityService tenantPsychologicalAcvitityService;
    @Autowired
    private TenantPsychologicalCounselingService tenantPsychologicalCounselingService;
    @Autowired
    private TenantOrderInfoService tenantOrderInfoService;
    @Autowired
    private TenantUsersService tenantUsersService;
    @Autowired
    private ExtPsychologistService extPsychologistService;
    @Autowired
    private TenantOrderPsychologistService tenantOrderPsychologistService;
    @Autowired
    private TenantFrameworksService tenantFrameworksService;
    @Autowired
    private TenantLogsService tenantLogsService;
    @Autowired
    private TenantNoticesService tenantNoticesService;
    @Autowired
    private SysTenantsService sysTenantsService;
    @Autowired
    private AdminUserService adminUserService;
    @Autowired
    private TenantPsychologicalCaseWarningFeedbackService mTenantPsychologicalCaseWarningFeedbackService;

    @Value("${server.absolute.path}")
    private String saveFilePath;


    /**
     * 跳转到上级管理员心理老师排班
     *
     * @param admin_uuid
     * @return
     */
    @RequestMapping("/gotoOrderSetByAdminPage")
    @ResponseBody
    public Map<String, Object> gotoOrderSetByAdminPage(@RequestParam(required = true) String admin_uuid) {
        AdminUser user = getAdminUserInfoByUuid(admin_uuid);
        Map<String, Object> model = new HashMap<String, Object>();
        List<TenantOrderPsychologist> psychologistlist = new ArrayList<TenantOrderPsychologist>();

        Map<String, Object> mapuser = new HashMap<String, Object>();
        mapuser.put("channel_id", user.getChannel_id());
        mapuser.put("user_type", 2);

        List<AdminUser> userlist = adminUserService.listAllAdminUsersByMap(mapuser);
        if (userlist.size() > 0) {
            psychologistlist = tenantOrderPsychologistService.listPsychologistsbyPsyid(userlist.get(0).getUuid());
        }
        model.put("userlist", userlist);
        model.put("psychologistlist", psychologistlist);
        model.put("psylistsize", psychologistlist.size());
        model.put("framework_id", user.getFramework_id());
        return model;
    }

    /**
     * 跳转到心理老师预约日历页
     *
     * @param request
     * @return
     */
    @RequestMapping("/gotoOrderInfoPage")
    @ResponseBody
    public Map<String, Object> gotoOrderInfoPage(HttpServletRequest request, @RequestParam(required = true) String admin_uuid) {
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        AdminUser user = getAdminUserInfoByUuid(admin_uuid);
        Map<String, Object> model = new HashMap<String, Object>();
        List<TenantOrderPsychologist> psychologistlist = new ArrayList<TenantOrderPsychologist>();
        Map<String, Object> mapuser = new HashMap<String, Object>();

        PageInfo pi = new PageInfo();
        if (user.getUser_type() == 2) {
            psychologistlist = tenantOrderPsychologistService.listPsychologistsbyPsyid(user.getUuid());
            mapuser.put("framework_id", user.getFramework_id());
            List<AdminUser> psychologistuser = new ArrayList<AdminUser>();
            psychologistuser.add(user);
            model.put("user", psychologistuser);
            model.put("usersize", 1);
            model.put("userdefaultid", psychologistuser.get(0).getUuid());
        } else {
            Map<String, Object> map = new HashMap<String, Object>();
            getframeworkDatas(user.getFramework_id(), user, map);
            psychologistlist = tenantOrderPsychologistService.listPsychologists(pi, map);
            map.put("user_type", 2);
            List<AdminUser> psychologistuser = adminUserService.listAllAdminUsersByMap(map);
            model.put("user", psychologistuser);
            model.put("usersize", psychologistuser.size());
            if (psychologistuser.size() > 0) {
                model.put("userdefaultid", psychologistuser.get(0).getUuid());
            } else {
                model.put("userdefaultid", 0);
            }
        }
        model.put("psychologistlist", psychologistlist);
        model.put("framework_id", user.getFramework_id());
        return model;
    }

    /**
     * 新增排班日期后方法
     */
    @RequestMapping(value = "/addOrderDate")
    @ResponseBody
    public AjaxJson addOrderDate(HttpServletRequest request, String examplelimit, @RequestParam(required = true) String admin_uuid, String channel_id,
                                 Integer is_scustom, String mon_times, String tue_times, String wed_times, String thu_times,
                                 String fri_times, String sat_times, String sun_times, String open_week2) {
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        AjaxJson aj = new AjaxJson();
        if (is_scustom == null) {
            is_scustom = 0;
        }
        if (is_scustom == 1 && (open_week2 == null || "".equals(open_week2))) {
            aj.setSuccess(false);
            return aj;
        }
//		User user = (User) SecurityUtils.getSubject().getPrincipal();
        AdminUser user = getAdminUserInfoByUuid(admin_uuid);
        List<TenantOrderPsychologist> psychologist = new ArrayList<TenantOrderPsychologist>();
        psychologist = tenantOrderPsychologistService.listPsychologistsbyPsyid(admin_uuid);
        if (psychologist.size() > 0) {
            psychologist.get(0).setOpen_week(examplelimit);
            psychologist.get(0).setPsychologist_id(admin_uuid);
            psychologist.get(0).setChannel_id(channel_id);
            psychologist.get(0).setEnabled(1);
            psychologist.get(0).setIs_scustom(is_scustom);
            psychologist.get(0).setOpen_week2(open_week2);
            if (mon_times != null && !"".equals(mon_times))
                psychologist.get(0).setMon_times(mon_times);
            if (tue_times != null && !"".equals(tue_times))
                psychologist.get(0).setTue_times(tue_times);
            if (wed_times != null && !"".equals(wed_times))
                psychologist.get(0).setWed_times(wed_times);
            if (thu_times != null && !"".equals(thu_times))
                psychologist.get(0).setThu_times(thu_times);
            if (fri_times != null && !"".equals(fri_times))
                psychologist.get(0).setFri_times(fri_times);
            if (sat_times != null && !"".equals(sat_times))
                psychologist.get(0).setSat_times(sat_times);
            if (sun_times != null && !"".equals(sun_times))
                psychologist.get(0).setSun_times(sun_times);
            tenantOrderPsychologistService.updateByPrimaryKey(psychologist.get(0));
            aj.setMsg("预约日期设置成功！");
            aj.setSuccess(true);
        } else {
            TenantOrderPsychologist psychologistlist = new TenantOrderPsychologist();
            psychologistlist.setOpen_week(examplelimit);
            psychologistlist.setPsychologist_id(admin_uuid);
            psychologistlist.setChannel_id(channel_id);
            psychologistlist.setEnabled(1);
            psychologistlist.setIs_scustom(is_scustom);
            psychologistlist.setOpen_week2(open_week2);
            if (mon_times != null && !"".equals(mon_times))
                psychologistlist.setMon_times(mon_times);
            if (tue_times != null && !"".equals(tue_times))
                psychologistlist.setTue_times(tue_times);
            if (wed_times != null && !"".equals(wed_times))
                psychologistlist.setWed_times(wed_times);
            if (thu_times != null && !"".equals(thu_times))
                psychologistlist.setThu_times(thu_times);
            if (fri_times != null && !"".equals(fri_times))
                psychologistlist.setFri_times(fri_times);
            if (sat_times != null && !"".equals(sat_times))
                psychologistlist.setSat_times(sat_times);
            if (sun_times != null && !"".equals(sun_times))
                psychologistlist.setSun_times(sun_times);
            tenantOrderPsychologistService.insertSelective(psychologistlist);
            aj.setMsg("预约日期更新成功！");
            aj.setSuccess(true);
        }

        return aj;
    }

    /**
     * 获取咨询师排班信息
     *
     * @param psychologist_id
     * @return
     */
    @RequestMapping("/listPsychologistsbyPsyidForMB")
    @ResponseBody
    public ResponseData listPsychologistsbyPsyidForMB(String psychologist_id) {
        TenantOrderPsychologist psychologist = new TenantOrderPsychologist();
        Map<String, Object> map = new HashMap<String, Object>();
        ResponseData mResponseData = new ResponseData();
        try {
            List<TenantOrderPsychologist> psyitem = new ArrayList<TenantOrderPsychologist>();
            psyitem = tenantOrderPsychologistService.listPsychologistsbyPsyid(psychologist_id);
            if (psyitem != null && psyitem.size() == 0) {
                mResponseData.setMsg("暂无数据");
                return mResponseData;
            }
            map.put("psychologist", psyitem.get(0));
            mResponseData.setData(map);
        } catch (Exception e) {
            e.printStackTrace();

        }
        return mResponseData;
    }

    /**
     * 普通用户预约编辑
     */
    @RequestMapping(value = "/editCustomOrder", method = RequestMethod.POST)
    @ResponseBody
    public AjaxJson editCustomOrder(HttpServletRequest request, String orderdate, String ordertime, String user_uuid,
                                    String psyid, Integer status, String oldordertime, Long orderid, String ordertype) {
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        TenantOrderInfo orderinfo = new TenantOrderInfo();
        AjaxJson aj = new AjaxJson();
        EUser user = getUserInfoByUuid(user_uuid);
        Integer flagalter = 1;// 默认可以修改

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        orderinfo.setOrder_time(ordertime);
        orderinfo.setUser_uuid(user_uuid);
        orderinfo.setPsychologist_id(psyid);
        orderinfo.setStatus(status);

        String time = DateTimeUtil.getNowString();
        orderinfo.setCreate_date(DateTimeUtil.getUtcFromStrings(time));
        Map<String, Object> returnmap = new HashMap<String, Object>();

        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("psychologist_id", psyid);
            map.put("order_date", DateTimeUtil.getUtcFromStrings(orderdate + " 00:00:00") / 1000);
            map.put("order_time", ordertime);
            List<TenantOrderInfo> OrderInfoList = tenantOrderInfoService.listAllOrderInfos(null, map);
            if (OrderInfoList.size() > 0) {
                for (int i = 0; i < OrderInfoList.size(); i++) {
                    if (OrderInfoList.get(i).getStatus() == 0 || OrderInfoList.get(i).getStatus() == 1) {
                        // 不能修改
                        flagalter = 2;
                    }
                }
            }
            String dateweek = DateUtil.dateToWeek(orderdate);
            TenantOrderPsychologist psychologist = tenantOrderPsychologistService.getPsychologistsbyPsyid(psyid);
            if (psychologist != null) {
                int IsCustom = psychologist.getIs_scustom();
                if (IsCustom == 0) {
                    if (psychologist.getOpen_week().indexOf(dateweek) == -1) {
                        // 不能修改
                        flagalter = 0;
                    }
                } else if (IsCustom == 1) {
                    if (psychologist.getOpen_week2().indexOf(dateweek) == -1) {
                        // 不能修改
                        flagalter = 0;
                    }
                }
            } else {
                // 不能修改
                flagalter = 0;
            }

            if (flagalter == 1) {
                Date orderdatenew = format.parse(orderdate);
                orderinfo.setOrder_date(orderdatenew.getTime() / 1000);
                tenantOrderInfoService.insert(orderinfo);
                returnmap.put("flagalter", flagalter);
                aj.setAttributes(returnmap);
                aj.setSuccess(true);
                aj.setMsg("预约成功！");

                // 将之前的预约信息取消掉
                TenantOrderInfo orderinfoedit = new TenantOrderInfo();
                orderinfoedit.setId(orderid);
                orderinfoedit.setStatus(4);
                tenantOrderInfoService.updateByPrimaryKeySelective(orderinfoedit);

                if (ordertype == "custom") {
                    TenantNotices notice = new TenantNotices();
                    notice.setUser_uuid(psyid);
                    notice.setContent("您有预约信息：" + user.getReal_name() + "在" + DateTimeUtil.getNowString()
                            + "发送预约修改申请！请及时查看和审批预约信息。");
                    notice.setReaded(0);
                    tenantNoticesService.insert(notice);

                } else {
                    TenantNotices notice = new TenantNotices();
                    notice.setUser_uuid(user_uuid);
                    notice.setContent(
                            "您有预约信息：" + user.getReal_name() + "在" + DateTimeUtil.getNowString() + "发送预约修改！请及时查看预约信息。");
                    notice.setReaded(0);
                    tenantNoticesService.insert(notice);
                }
                // 预约咨询增量推送
                pushStatAppiont(user.getChannel_id(), user.getFramework_id());
            } else {
                returnmap.put("flagalter", flagalter);
                aj.setSuccess(true);
                aj.setAttributes(returnmap);
                aj.setMsg("当前时间不可约，请选择其他时间！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            // log.debug(e.getMessage());
            aj.setSuccess(false);
            aj.setMsg("预约失败！");
        }

        return aj;
    }

    // 预约咨询增量推送
    private void pushStatAppiont(String channel_id, Long framework_id) {

    }

    /**
     * 审批预约状态
     *
     * @param orderid 租户id
     * @return
     */
    @RequestMapping(value = "/updateOrder", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> updateOrder(HttpServletRequest request, Long orderid, int status, Long userid) {
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        Map<String, Object> map = new HashMap<String, Object>();
//		User user = (User) SecurityUtils.getSubject().getPrincipal();
        TenantUsers user = getUserInfoById(String.valueOf(userid));
        try {
            TenantOrderInfo orderinfo = new TenantOrderInfo();
            orderinfo.setId(orderid);
            orderinfo.setStatus(status);
            tenantOrderInfoService.updateByPrimaryKeySelective(orderinfo);
            map.put("bool", true);
            map.put("msg", "预约审批成功");
            TenantNotices notice = new TenantNotices();
            notice.setUser_id(userid);
            if (status == 1) {
                notice.setContent("你有预约信息：在" + DateTimeUtil.getNowString() + "老师审批通过！请按时去咨询，谢谢！");
            } else {
                notice.setContent("你有预约信息：在" + DateTimeUtil.getNowString() + "老师审批没有通过！");
            }
            notice.setReaded(0);
            tenantNoticesService.insert(notice);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("bool", false);
            map.put("msg", "预约审批失败");
        }

        return map;
    }


    /**
     * 列表ajax获取数据（日历页面）
     *
     * @param psyid
     * @return OrderInfoList数据格式json
     */
    @RequestMapping("/selectOrderInfoByAdmin")
    @ResponseBody
    public List<TenantOrderInfo> selectOrderInfoByAdmin(String psyid) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("psychologist_id", psyid);
        List<TenantOrderInfo> OrderInfoList = tenantOrderInfoService.listAllOrderInfos(null, map);
        return OrderInfoList;
    }

    /**
     * 列表ajax获取数据
     *
     * @param psychologist_id
     * @return OrderInfoList数据格式json
     */
    @RequestMapping("/orderDetailInfo")
    @ResponseBody
    public List<TenantOrderInfo> orderDetailInfo(HttpServletRequest request, long order_date, String psychologist_id,
                                                 int pagesize, int pagecount, String user_id) {
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        TenantUsers user = getUserInfoById(user_id);
        Map<String, Object> map = new HashMap<String, Object>();
        PageInfo pi = new PageInfo();
        pi.setCurrentPage(pagesize);
        pi.setPageSize(pagecount);
        map.put("psychologist_id", psychologist_id);
        map.put("order_date", order_date);
        List<TenantOrderInfo> OrderInfoList = tenantOrderInfoService.listAllOrderInfos(null, map);

        try {
            Map<String, Object> maptemp = new HashMap<String, Object>();
            for (int i = 0; i < OrderInfoList.size(); i++) {
                maptemp.put("id", OrderInfoList.get(i).getUser_id());
//				User usertemp = userService.getUserInfo(maptemp);
                TenantUsers usertemp = getUserInfoById(String.valueOf(OrderInfoList.get(i).getUser_id()));
                OrderInfoList.get(i).setPsychologist_name(usertemp.getReal_name());
                OrderInfoList.get(i).setUser_gender(usertemp.getUser_gender());

                Map<String, Object> p_maps = new HashMap<String, Object>();
                p_maps.put("id", usertemp.getFramework_id());
                long frameworkid = usertemp.getFramework_id();
                TenantFrameworks framework = tenantFrameworksService.getFrameworkById(frameworkid);
                if (framework != null) {
                    OrderInfoList.get(i).setWhole_name(framework.getWhole_name());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();

        }
        return OrderInfoList;
    }

    /*
     * 根据姓名进行查找面询记录
     */
    @RequestMapping("/selectMx")
    @ResponseBody
    public TenantOrderRecord selectMx(long id, long order_id) {
        AjaxJson aj = new AjaxJson();
        /* long user_id=Long.valueOf(id); */
        PageInfo pi = new PageInfo();
        Map<String, Object> map = new HashMap<String, Object>();
        if (id != 0) {
            map.put("id", id);
        }
        if (order_id != 0) {
            map.put("order_id", order_id);
        }
        TenantOrderRecord order = tenantOrderRecordService.listAllOrderRecords(pi, map).get(0);
        if (order != null) {
            Map<String, Object> maptemp = new HashMap<String, Object>();
            maptemp.put("record", order.getRecord());
            maptemp.put("image_url", order.getImage_url());
            maptemp.put("media_url", order.getMedia_url());
            maptemp.put("orderrecord", order);
            aj.setSuccess(true);
            aj.setAttributes(maptemp);
        } else {
            aj.setSuccess(false);
            aj.setAttributes(null);
        }
        return order;
    }


    @RequestMapping("/getUserinfoBycode")
    @ResponseBody
    public AjaxJson getUserinfoBycode(int page, String code) {
        AjaxJson aj = new AjaxJson();
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> p_map = new HashMap<String, Object>();
        Map<String, Object> p_maps = new HashMap<String, Object>();
        map.put("code", code);
        PageInfo pi = new PageInfo();
        pi.setPageSize(1);
        pi.setCurrentPage(page);
        List<TenantOrderRecord> record = tenantOrderRecordService.listOrderRecordByCode(pi, map);
        p_map.put("record", record);
        p_maps.put("code", code);
        long count = tenantOrderRecordService.listOrderRecordByCodeCount(p_maps);
        p_map.put("count", count);
        aj.setAttributes(p_map);
        return aj;
    }


    /**
     * 历史面谈记录方案中
     */
    @RequestMapping("/datagridMTList")
    @ResponseBody
    public ResponseData datagridMTList(HttpServletRequest request, Integer page, Integer page_size, String user_uuid, long record_id) {
        ResponseData responseData = new ResponseData();
        Map<String, Object> retmap = new HashMap<String, Object>();
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        PageInfo pi = new PageInfo();
        Map<String, Object> map = new HashMap<String, Object>();
        if (page != null && page_size != null) {
            pi.setCurrentPage(page);
            pi.setPageSize(page_size);
        }
        map.put("user_uuid", user_uuid);
        long count = tenantOrderRecordService.listAllOrderRecordsPageCount(map);
        List<TenantOrderRecord> list = tenantOrderRecordService.listAllOrderRecords(pi, map);

        if (record_id != 0) // 预约过来的用户
        {
            Map<String, Object> maptemp = new HashMap<String, Object>();
            maptemp.put("id", record_id);
            List<TenantOrderRecord> orderrecordlist = tenantOrderRecordService.listAllOrderRecords(pi, maptemp);
            if (orderrecordlist.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getId() == orderrecordlist.get(0).getId()) {
//                        dataGrid.setOtherParam(orderrecordlist.get(0));
                        retmap.put("otherParam", orderrecordlist.get(0));
                        // list.remove(i);
                        // count--;
                    }
                }
            }
        }

        if (record_id == 0) {
            Map<String, Object> maptemp = new HashMap<String, Object>();
            maptemp.put("user_uuid", user_uuid);
            List<TenantOrderRecord> orderrecordlist = tenantOrderRecordService.listAllOrderRecords(pi, maptemp);
            if (orderrecordlist.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getId().equals(orderrecordlist.get(0).getId())) {
//                        dataGrid.setOtherParam(orderrecordlist.get(0));
                        retmap.put("otherParam", orderrecordlist.get(0));
                        // list.remove(i);
                        // count--;
                    }
                }
            }
        }
        Map<String, Object> maptemp = new HashMap<String, Object>();
        // 获取用户表的真实姓名
        for (int j = 0; j < list.size(); j++) {
//			maptemp.put("id", list.get(j).getUser_id());
//			User usertemp = userService.getUserInfo(maptemp);
            EUser usertemp = getUserInfoByUuid(String.valueOf(list.get(j).getUser_uuid()));
            list.get(j).setName(usertemp.getReal_name());
//			maptemp.put("id", list.get(j).getPsychologist_id());
//			User usertemp2 = userService.getUserInfo(maptemp);
            AdminUser usertemp2 = getAdminUserInfoByUuid(String.valueOf(list.get(j).getPsychologist_id()));
            list.get(j).setPsychologist_name(usertemp2.getReal_name());
        }
        retmap.put("list", list);
        retmap.put("count", count);
        responseData.setData(retmap);
        return responseData;
    }

//	/*
//	 * 根据姓名进行查找面询记录
//	 */
//	/*
//	 * @RequestMapping("selectMX")
//	 *
//	 * @ResponseBody public AjaxJson selectMX(String id){ AjaxJson aj=new
//	 * AjaxJson(); System.out.println(id+"88"); long user_id=Long.valueOf(id); User
//	 * user=userService.getUserById(user_id); Map<String, Object> map1 = new
//	 * HashMap<String, Object>(); OrderRecord
//	 * order=orderService.listAllOrderRecordsByuser_id(user.getId());
//	 * if(order!=null){ System.out.println(order.getRecord()+"9898");
//	 * aj.setSuccess(true); Map<String, Object> map = new HashMap<String, Object>();
//	 *
//	 * map.put("tt", "666"); map.put("record", order.getRecord());
//	 * map.put("image_url", order.getImage_url()); map.put("media_url",
//	 * order.getMedia_url()); aj.setSuccess(true); aj.setAttributes(map); }else{
//	 * aj.setSuccess(false); aj.setAttributes(null); }
//	 *
//	 * return aj; }
//	 */
//	@RequestMapping("selectMxCount")
//	@ResponseBody
//	public List<Map<String, Object>> selectMxCount(String user_id) {
//		List<Map<String, Object>> listMx = getBigTenantOrderAnalyze(user_id);
//		return listMx;
//	}

    /*
     * 根据下属单位查询咨询师
     * 未使用
     */
    @RequestMapping(value = "/getAllPsyInfo")
    @ResponseBody
    public List<AdminUser> getAllPsyInfo(HttpServletRequest request, Integer page, Integer page_size, long framework_id, String admin_uuid) {
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        Map<String, Object> map = new HashMap<String, Object>();
        AdminUser operator = getAdminUserInfoByUuid(admin_uuid);
        getframeworkDatas(framework_id, operator, map);
        map.put("user_type", 2);
        List<AdminUser> list = adminUserService.listAllAdminUsersByMap(map);
        for (int i = 0; i < list.size(); i++) {
            ExtPsychologist psy = new ExtPsychologist();
            psy = extPsychologistService.selectExtPsyInfoByUserUuid(list.get(i).getUuid());
            if (psy != null) {
                list.get(i).setGood_at(psy.getGood_at());
            } else {
                list.get(i).setGood_at("未设置");
            }
            if (list.get(i).getUuid() == operator.getUuid()) {
                AdminUser usertemp = new AdminUser();
                usertemp = list.get(0);
                list.set(0, list.get(i));
                list.set(i, usertemp);
            }
        }
        return list;
    }

    /**
     * 导出面询详情
     *
     * @param response
     */
    @RequestMapping("converWord")
    public void converWord(HttpServletResponse response, String htmlcontent, String wordname) {
        wordname = "面询详情.doc";

        try {
            String title = new String(wordname.getBytes("gbk"), "ISO8859-1");
            response.setHeader("Content-disposition", "attachment;filename=" + title);
            response.setCharacterEncoding("UTF-8");

            byte b[] = htmlcontent.getBytes("UTF-8");
            ServletOutputStream servletOS = response.getOutputStream();
            servletOS.write(b);
            servletOS.flush();
            servletOS.close();
            servletOS = null;
            return;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return;
    }

    /**
     * 添加个案
     *
     * @param psychologist_id 咨询师id
     * @param user_uuid       咨询者uuid
     * @param distribution:   年龄分布 :小学......
     * @param user_gender     性别 1：男 2：女
     * @param real_name       咨询者真实姓名
     * @param
     * @return
     */
    @RequestMapping(value = "/addCase")
    @ResponseBody
    public ResponseData addCase(@RequestParam(required = true) String psychologist_id,
                                @RequestParam(required = true) String user_uuid,
                                @RequestParam(required = true) String distribution,
                                Integer user_gender, String real_name) {
        ResponseData reData = new ResponseData();
        if (StringUtils.isEmpty(psychologist_id)) {
            reData.setCode(-1);
            reData.setMsg("psychologist_id为空!");
            return reData;
        }
        if (StringUtils.isEmpty(user_uuid)) {
            reData.setCode(-1);
            reData.setMsg("user_uuid为空!");
            return reData;
        }
        if (StringUtils.isEmpty(distribution)) {
            reData.setCode(-1);
            reData.setMsg("distribution为空!");
            return reData;
        }
        AdminUser operator = getAdminUserInfoByUuid(psychologist_id);

        if (operator == null) {
            reData.setCode(-1);
            reData.setMsg("登录信息失效!");
            return reData;
        }
        Map<String, Object> map = new HashMap<String, Object>();

        EUser userInfoByUuid = getUserInfoByUuid(user_uuid);
        if (userInfoByUuid == null) {
            reData.setCode(-1);
            reData.setMsg("咨询者信息为空!");
            return reData;
        }
        TenantFrameworks frameworkById = tenantFrameworksService.getFrameworkById(userInfoByUuid.getFramework_id());
        try {
            map.put("psychologist_id", psychologist_id);
            map.put("user_uuid", user_uuid);
            List<Map<String, Object>> list = tenantPsychologicalCaseService.listPsychologicalCaseByMap(null, map);
            if (list.size() == 0) {
                Date mDate = new Date();
                TenantPsychologicalCase mPsychologicalCase = new TenantPsychologicalCase();
                mPsychologicalCase.setCreate_date(mDate.getTime() / 1000);
                mPsychologicalCase.setUpdate_date(mDate.getTime() / 1000);
                mPsychologicalCase.setPsychologist_id(operator.getUuid());
                mPsychologicalCase.setUser_uuid(user_uuid);
                mPsychologicalCase.setFramework_id(operator.getFramework_id());
                mPsychologicalCase.setDistribution(distribution);
                mPsychologicalCase.setUser_gender(user_gender);
                mPsychologicalCase.setReal_name(real_name);
                mPsychologicalCase.setWhole_name(frameworkById.getWhole_name());
                mPsychologicalCase.setEnabled(1);
                mPsychologicalCase.setFinished(0);
                String mCounseling_onlyid = operator.getChannel_id() + mDate.getTime() / 1000;
                mPsychologicalCase.setCounseling_onlyid(mCounseling_onlyid);
                tenantPsychologicalCaseService.insert(mPsychologicalCase);
                map.clear();
                map.put("counseling_onlyid", mCounseling_onlyid);
                map.put("case_id", mPsychologicalCase.getId());
                reData.setData(map);
            } else {
                reData.setCode(-1);
                reData.setMsg("已存在个案!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("添加咨询失败!");
        }
        return reData;
    }

    /**
     * 删除个案
     *
     * @param case_id
     * @return
     */
    @RequestMapping(value = "/deleteCase")
    @ResponseBody
    public ResponseData deleteCase(@RequestParam(required = true) Long case_id, @RequestParam(required = true) String admin_uuid) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        if (case_id == null) {
            reData.setCode(-1);
            reData.setMsg("个案id为空,无法删除个案!");
            return reData;
        }
        if (admin_uuid == null || "".equals(admin_uuid)) {
            reData.setCode(-1);
            reData.setMsg("咨询师id为空,无法删除个案!");
            return reData;
        }
        try {
            AdminUser operator = getAdminUserInfoByUuid(admin_uuid);
            map.put("id", case_id);
            TenantPsychologicalCase mPsychologicalCase = tenantPsychologicalCaseService.getPsychologicalCaseById(map);
            tenantPsychologicalCaseService.delPsychologicalCase(case_id);
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("删除个案失败!");
        }
        return reData;
    }

    /**
     * 获取个案
     *
     * @param case_id
     * @param counseling_onlyid
     * @return
     */
    @RequestMapping(value = "/getCaseByid")
    @ResponseBody
    public ResponseData getCaseByid(Long case_id, String counseling_onlyid) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap();
        if (case_id == null && (StringUtils.isEmpty(counseling_onlyid))) {
            reData.setCode(-1);
            reData.setMsg("个案id为空,无法查找个案!");
            return reData;
        }

        if (counseling_onlyid != null && !"".equals(counseling_onlyid)) {
            map.put("counseling_onlyid", counseling_onlyid);
        }
        if (case_id != null && !"".equals(case_id)) {
            map.put("id", case_id);
        }
        try {
            TenantPsychologicalCase mPsychologicalCase = tenantPsychologicalCaseService.getPsychologicalCaseById(map);
            map.clear();
            map.put("PsychologicalCase", mPsychologicalCase);
            reData.setData(map);
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("查找个案失败!");
        }
        return reData;
    }

    /**
     * 获取个案列表
     *
     * @param counseling_onlyid
     * @param psychologist_id
     * @param framework_id
     * @param test_begin_date
     * @param test_end_date
     * @param real_name
     * @param user_gender
     * @return
     */
    @RequestMapping("/getCaseList")
    @ResponseBody
    public ResponseData getCaseList(Integer page, Integer page_size, String counseling_onlyid,
                                    String psychologist_id, String distribution, Long framework_id,
                                    String test_begin_date, String test_end_date,
                                    String real_name, Integer user_gender, String user_uuid,
                                    @RequestParam(required = true) String admin_uuid, Integer old) {

        PageInfo pi = new PageInfo();
        ResponseData mResponseData = new ResponseData();

        AdminUser operator = getAdminUserInfoByUuid(admin_uuid);

        Map<String, Object> map = new HashMap<String, Object>();
        if (user_uuid != null) {
            map.put("user_uuid", user_uuid);
        }
        if (old != null && old == 1) {
            map.put("old", old);
        } else {
            if (!StringUtils.isEmpty(counseling_onlyid)) {
                map.put("counseling_onlyid", counseling_onlyid);
            }

            if (!StringUtils.isEmpty(psychologist_id)) {
                map.put("psychologist_id", psychologist_id);
            }
//            getframeworkDatas(framework_id, operator, map);
            getTreePathDatas(framework_id, operator, map);
            if (test_begin_date != null && !"".equals(test_begin_date)) {
                map.put("test_begin_date", DateTimeUtil.getUtcFromString(test_begin_date));
            }
            if (test_end_date != null && !"".equals(test_end_date)) {
                map.put("test_end_date", DateTimeUtil.getEndUtcFromString(test_end_date));
            }

            if (!StringUtils.isEmpty(real_name)) {
                map.put("real_name", real_name);
                map.put("searchName", real_name);
            }

            if (!StringUtils.isEmpty(distribution)) {
                map.put("distribution", distribution);
            }
            if (user_gender != null) {
                map.put("user_gender", user_gender);
            }
        }

        if (page != null && page_size != null) {
            pi.setCurrentPage(page);
            pi.setPageSize(page_size);
        }
        try {
            List<Map<String, Object>> mPsychologicalCounselingList = tenantPsychologicalCaseService
                    .listPsychologicalCaseByMap(pi, map);
            long mCount = tenantPsychologicalCaseService.listPsychologicalCaseCount(map);

            map.clear();
            map.put("list", mPsychologicalCounselingList);
            map.put("limCountst", mCount);
            mResponseData.setData(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mResponseData;
    }

    /**
     * 添加资源
     *
     * @param cl_file
     * @param counseling_onlyid
     * @return
     */
    @RequestMapping(value = "/addCounselingResource")
    @ResponseBody
    public ResponseData addCounselingResource(@RequestParam("cl_file") MultipartFile cl_file,
                                              String counseling_onlyid, @RequestParam(required = true) String admin_uuid) {
        ResponseData reData = new ResponseData();
//		User operator = (User) SecurityUtils.getSubject().getPrincipal();
        AdminUser adminUserInfoByUuid = getAdminUserInfoByUuid(admin_uuid);
        Map<String, Object> map = new HashMap<String, Object>();
        String filePath;
        String fileName = "";
        String newFileName;

        if (counseling_onlyid == null || "".equals(counseling_onlyid)) {
            reData.setCode(-1);
            reData.setMsg("个案编号不能为空!");
            return reData;
        }
        MultipartFile file = cl_file;
        // 保存文件
        if (!file.isEmpty()) {
            try {
                filePath = saveFilePath + "counseling/" + counseling_onlyid + "/";
                File dir = new File(filePath);
                if (!dir.isDirectory())
                    dir.mkdirs();
                String fileOriginalName = file.getOriginalFilename();
                newFileName = fileOriginalName;
                file.transferTo(new File(filePath + newFileName));
                fileName += "/counseling/" + counseling_onlyid + "/" + newFileName;
                map.put("fileName", fileName);
                reData.setData(map);
            } catch (IOException e) {
                e.printStackTrace();
                reData.setCode(-1);
                reData.setMsg("资源文件保存失败!");
                return reData;
            }
        } else {
            reData.setCode(-1);
            reData.setMsg("资源文件为空!");
            return reData;
        }
        return reData;
    }

    /**
     * 删除资源
     *
     * @param fileName
     * @return
     */
    @RequestMapping(value = "/delCounselingResource")
    @ResponseBody
    public ResponseData delCounselingResource(String fileName, @RequestParam(required = true) String admin_uuid) {
        ResponseData reData = new ResponseData();
        AdminUser operator = getAdminUserInfoByUuid(admin_uuid);
        try {
            File mFile = new File(saveFilePath + fileName);
            if (mFile.exists()) {
                mFile.delete();
            }
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("资源文件删除失败!");
            return reData;
        }
        return reData;
    }

    /**
     * 添加咨询
     *
     * @param fileNames         资源文件
     * @param counseling_onlyid 个案编号
     * @param case_id           个案id
     * @param manner            咨询方式
     * @param type              咨询类型
     * @param identity          身份
     * @param device            设备
     * @param counselin_time    咨询时间
     * @param description       描述
     * @param postscript        备注
     * @param next_date         下次咨询时间
     * @param count             咨询次数
     * @param main_suit         主诉
     * @param target            咨询目标
     * @param method            咨询方法
     * @param record            咨询过程
     * @param result_suggest    小结
     * @return
     */

    @RequestMapping(value = "/addCounseling")
    @ResponseBody
    public ResponseData addCounseling(String fileNames, String counseling_onlyid, Long case_id, String manner,
                                      String type, String identity, String device,
                                      String counselin_time, String description, String postscript, String next_date, Integer count,
                                      String main_suit, String target, String method, String record, String result_suggest,
                                      @RequestParam(required = true) String admin_uuid) {
        ResponseData reData = new ResponseData();
        AdminUser adminUser = getAdminUserInfoByUuid(admin_uuid);
        Map<String, Object> map = new HashMap<String, Object>();
        if (case_id == null) {
            reData.setCode(-1);
            reData.setMsg("个案id不能为空!");
            return reData;
        }
        if (counseling_onlyid == null || "".equals(counseling_onlyid)) {
            reData.setCode(-1);
            reData.setMsg("个案编号不能为空!");
            return reData;
        }
        if (StringUtils.isEmpty(counselin_time)) {
            reData.setCode(-1);
            reData.setMsg("咨询时间不能为空!");
            return reData;
        }
        try {
            Date mDate = new Date();
            TenantPsychologicalCounseling psychologicalCounseling = new TenantPsychologicalCounseling();
            psychologicalCounseling.setManner(manner);
            psychologicalCounseling.setUpdate_date(mDate.getTime() / 1000);
            psychologicalCounseling.setCreate_date(mDate.getTime() / 1000);
            psychologicalCounseling.setEnabled(1);
            if (!StringUtils.isEmpty(count))
                psychologicalCounseling.setCount(count);
            psychologicalCounseling.setCase_id(case_id);
            psychologicalCounseling.setResource(fileNames);
            if (!StringUtils.isEmpty(description))
                psychologicalCounseling.setDescription(description);
            if (!StringUtils.isEmpty(postscript))
                psychologicalCounseling.setPostscript(postscript);
            if (!StringUtils.isEmpty(main_suit))
                psychologicalCounseling.setMain_suit(main_suit);
            if (!StringUtils.isEmpty(target))
                psychologicalCounseling.setTarget(target);
            if (!StringUtils.isEmpty(method))
                psychologicalCounseling.setMethod(method);
            if (!StringUtils.isEmpty(record))
                psychologicalCounseling.setRecord(record);
            if (!StringUtils.isEmpty(type))
                psychologicalCounseling.setType(type);
            if (!StringUtils.isEmpty(identity))
                psychologicalCounseling.setIdentity(identity);
            if (!StringUtils.isEmpty(result_suggest))
                psychologicalCounseling.setResult_suggest(result_suggest);
            if (!StringUtils.isEmpty(device))
                psychologicalCounseling.setDevice(device);
            if (!StringUtils.isEmpty(next_date)) {
                psychologicalCounseling.setNext_date(DateTimeUtil.getUtcFromString(next_date));
            }
            if (!StringUtils.isEmpty(counselin_time)) {
                psychologicalCounseling.setCounselin_time(DateTimeUtil.getUtcFromString(counselin_time));
            } else {
                psychologicalCounseling.setCounselin_time(mDate.getTime() / 1000);
            }
            tenantPsychologicalCounselingService.insert(psychologicalCounseling);
            TenantPsychologicalCase tenantPsychologicalCase = new TenantPsychologicalCase();
            tenantPsychologicalCase.setUpdate_date(psychologicalCounseling.getCounselin_time());
            tenantPsychologicalCase.setId(case_id);
            tenantPsychologicalCaseService.updateByPrimaryKeySelective(tenantPsychologicalCase);
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("添加咨询失败!");
        }
        return reData;
    }

    /**
     * 获取 个案对应的咨询列表信息
     *
     * @param case_id 个案id
     * @return
     */
    @RequestMapping("/listCounselings")
    @ResponseBody
    public ResponseData listCounselings(@RequestParam(required = true) Long case_id) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        if (case_id == null) {
            reData.setCode(-1);
            reData.setMsg("个案id为空!");
            return reData;
        }
        map.put("case_id", case_id);
        try {
            List<TenantPsychologicalCounseling> mPsychologicalCounselingList = tenantPsychologicalCounselingService
                    .listPsychologicalCounselingByMap(map);
            if (mPsychologicalCounselingList == null || mPsychologicalCounselingList.size() == 0) {
                reData.setMsg("暂无咨询");
                return reData;
            }
            for (int i = 0; i < mPsychologicalCounselingList.size(); i++) {
                if (mPsychologicalCounselingList.get(i).getWarning_id() != null) {
                    List<TenantPsychologicalCaseWarningFeedback> tenantPsychologicalCaseWarningFeedbacks = mTenantPsychologicalCaseWarningFeedbackService.listWarningFeedbackByWarningId(mPsychologicalCounselingList.get(i).getWarning_id());
                    if (tenantPsychologicalCaseWarningFeedbacks != null) {
                        mPsychologicalCounselingList.get(i).setFeedbackList(tenantPsychologicalCaseWarningFeedbacks);
                    }
                }
            }
            map.put("size", mPsychologicalCounselingList.size());
            map.put("data", mPsychologicalCounselingList);
            reData.setData(map);
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("获取咨询失败");
        }
        return reData;
    }

    /**
     * 通过id获取咨询
     *
     * @param counseling_id
     * @return
     */
    @RequestMapping("/getCounselingByid")
    @ResponseBody
    public ResponseData getCounselingByid(@RequestParam(required = true) Long counseling_id) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        if (counseling_id == null) {
            reData.setCode(-1);
            reData.setMsg("咨询id为空!");
            return reData;
        }
        map.put("case_id", counseling_id);
        try {
            TenantPsychologicalCounseling mPsychologicalCounseling = tenantPsychologicalCounselingService.selectByPrimaryKey(counseling_id);
            map.put("data", mPsychologicalCounseling);
            reData.setData(map);
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("获取咨询失败");
        }
        return reData;
    }

    /**
     * 更新咨询
     *
     * @param fileNames         资源文件
     * @param counseling_onlyid 个案编号
     * @param case_id           个案id
     * @param manner            咨询方式
     * @param counselin_time    咨询时间
     * @param description       描述
     * @param postscript        备注
     * @param next_date         下次咨询时间
     * @param count             当前次数
     * @param counseling_id     咨询id
     * @param main_suit         主诉
     * @param target            目标
     * @param method            方法
     * @param record            过程
     * @param result_suggest    小结 (预留)
     * @return
     */
    @RequestMapping(value = "/updateCounseling")
    @ResponseBody
    public ResponseData updateCounseling(String fileNames, String counseling_onlyid, Long case_id, String manner,
                                         String counselin_time, String description, String postscript, String next_date, Integer count,
                                         @RequestParam(required = true) Long counseling_id, String main_suit, String target, String method,
                                         String type, String identity, String device, String record, String result_suggest, @RequestParam(required = true) String admin_uuid) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        TenantPsychologicalCounseling tenantPsychologicalCounseling = new TenantPsychologicalCounseling();
        if (counseling_id == null) {
            reData.setCode(-1);
            reData.setMsg("咨询id不能为空!");
            return reData;
        }
        Date mDate = new Date();
        if (!StringUtils.isEmpty(manner))
            tenantPsychologicalCounseling.setManner(manner);
        if (!StringUtils.isEmpty(counselin_time))
            tenantPsychologicalCounseling.setCounselin_time(DateTimeUtil.getUtcFromString(counselin_time));
        tenantPsychologicalCounseling.setUpdate_date(mDate.getTime() / 1000);
        if (!StringUtils.isEmpty(count))
            tenantPsychologicalCounseling.setCount(count);
        if (!StringUtils.isEmpty(next_date))
            tenantPsychologicalCounseling.setNext_date(DateTimeUtil.getUtcFromString(next_date));
        if (!StringUtils.isEmpty(description))
            tenantPsychologicalCounseling.setDescription(description);
        if (!StringUtils.isEmpty(postscript))
            tenantPsychologicalCounseling.setPostscript(postscript);
        tenantPsychologicalCounseling.setResource(fileNames);
        if (!StringUtils.isEmpty(main_suit))
            tenantPsychologicalCounseling.setMain_suit(main_suit);
        if (!StringUtils.isEmpty(target))
            tenantPsychologicalCounseling.setTarget(target);
        if (!StringUtils.isEmpty(method))
            tenantPsychologicalCounseling.setMethod(method);
        if (!StringUtils.isEmpty(record))
            tenantPsychologicalCounseling.setRecord(record);

        if (!StringUtils.isEmpty(type))
            tenantPsychologicalCounseling.setType(type);
        if (!StringUtils.isEmpty(identity))
            tenantPsychologicalCounseling.setIdentity(identity);
        if (!StringUtils.isEmpty(device))
            tenantPsychologicalCounseling.setDevice(device);
        tenantPsychologicalCounseling.setId(counseling_id);
        try {
            int resultInt = tenantPsychologicalCounselingService.updateByPrimaryKeySelective(tenantPsychologicalCounseling);

            if (resultInt != 1) {
                reData.setCode(-1);
                reData.setMsg("更新失败失败!");
                return reData;
            }
            if (!StringUtils.isEmpty(counselin_time)) {
                TenantPsychologicalCase tenantPsychologicalCase = new TenantPsychologicalCase();
                tenantPsychologicalCase.setUpdate_date(DateTimeUtil.getUtcFromString(counselin_time));
                tenantPsychologicalCase.setId(case_id);
                tenantPsychologicalCaseService.updateByPrimaryKeySelective(tenantPsychologicalCase);
            }

        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("更新失败失败!");
        }
        return reData;
    }

    /**
     * 删除咨询
     *
     * @param counseling_id
     * @return
     */
    @RequestMapping(value = "/deleteCounseling")
    @ResponseBody
    public ResponseData deleteCounseling(@RequestParam(required = true) Long counseling_id, @RequestParam(required = true) String admin_uuid) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        if (counseling_id == null) {
            reData.setCode(-1);
            reData.setMsg("咨询id为空,无法删除个案!");
            return reData;
        }
        try {
            TenantPsychologicalCounseling mPsychologicalCounseling = tenantPsychologicalCounselingService
                    .selectByPrimaryKey(counseling_id);
            String mResource = mPsychologicalCounseling.getResource();
            if (mResource != null && mResource.contains("|")) {
                String[] mResourceList = mResource.split("\\|");
                for (int j = 0; j < mResourceList.length; j++) {
                    File mFile = new File(saveFilePath + mResourceList[j]);
                    if (mFile.exists()) {
                        mFile.delete();
                    }
                }
            }
            tenantPsychologicalCounselingService.delPsychologicalCounseling(counseling_id);
            TenantPsychologicalCounseling lastPsychologicalCounseling = tenantPsychologicalCounselingService.getLastPsychologicalCounseling(mPsychologicalCounseling.getCase_id());
            if (lastPsychologicalCounseling != null) {
                TenantPsychologicalCase tenantPsychologicalCase = new TenantPsychologicalCase();
                tenantPsychologicalCase.setUpdate_date(lastPsychologicalCounseling.getCounselin_time());
                tenantPsychologicalCase.setId(lastPsychologicalCounseling.getCase_id());
                tenantPsychologicalCaseService.updateByPrimaryKeySelective(tenantPsychologicalCase);
            } else {
                TenantPsychologicalCase tenantPsychologicalCase = tenantPsychologicalCaseService.selectByPrimaryKey(mPsychologicalCounseling.getCase_id());
                tenantPsychologicalCase.setUpdate_date(null);
                tenantPsychologicalCaseService.updateByPrimaryKey(tenantPsychologicalCase);
            }

        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("删除咨询失败!");
        }
        return reData;
    }

    /**
     * 新增活动
     *
     * @param activity_type   活动类型 :心理讲座、团体活动、参加培训、参加案例督导、仪器设备使用、新闻上传、校区级公开课、其他活动
     * @param activity_date   活动日期
     * @param psychologist_id 咨询师ID
     * @param admin_uuid      创建者id，
     * @return 选择活动类型（心理讲座、团体活动、参加培训、参加案例督导、仪器设备使用、新闻上传、校区级公开课、其他活动） 心理讲座
     * ---讲座类型选择（学生讲座、教师讲座、家长讲座、其他对象讲座） 团体活动
     * ---团体活动类型选择（社团活动、心理拓展课探究课、心理活动月活动、团体辅导活动、其他活动） 设备使用
     * ---设备类型（放松椅、宣泄仪、认知调节仪器、积极心理调节仪器、其他心理仪器）
     */
    @RequestMapping(value = "/addActivity")
    @ResponseBody
    public ResponseData addActivity(String activity_type, String activity_date, String psychologist_id,
                                    Integer upload, String title, String contents, @RequestParam(required = true) String admin_uuid) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        AdminUser operator = getAdminUserInfoByUuid(admin_uuid);
        if (StringUtils.isEmpty(activity_type)) {
            reData.setCode(-1);
            reData.setMsg("活动类型为空!");
            return reData;
        }
        if (StringUtils.isEmpty(activity_date)) {
            reData.setCode(-1);
            reData.setMsg("新增活动失败!活动日期为空!");
            return reData;
        }
        long framework_id;
        String channel_id;
        if (StringUtils.isEmpty(psychologist_id)) {
            psychologist_id = operator.getUuid();
            framework_id = operator.getFramework_id();
            channel_id = operator.getChannel_id();
        } else {
            AdminUser psychologistUser = getAdminUserInfoByUuid(psychologist_id);
            framework_id = psychologistUser.getFramework_id();
            channel_id = psychologistUser.getChannel_id();
        }

        if (upload == null) upload = 0;
        try {
            TenantPsychologicalAcvitity mPsychologicalAcvitity = new TenantPsychologicalAcvitity();
            mPsychologicalAcvitity.setActivity_type(activity_type);
            mPsychologicalAcvitity.setCreate_by(admin_uuid);
            mPsychologicalAcvitity.setCreate_date(new Date().getTime() / 1000);
            mPsychologicalAcvitity.setFramework_id(framework_id);
            mPsychologicalAcvitity.setTitle(title);
            mPsychologicalAcvitity.setUpload(upload);
            mPsychologicalAcvitity.setContents(contents);
            mPsychologicalAcvitity.setPsychologist_id(psychologist_id);
            mPsychologicalAcvitity.setActivity_date(DateTimeUtil.getUtcFromString(activity_date));

            tenantPsychologicalAcvitityService.insertSelective(mPsychologicalAcvitity);
            map.put("acvitityId", mPsychologicalAcvitity.getId());
            reData.setData(map);
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("新增活动失败!");
        }
        return reData;
    }

    /**
     * 删除活动
     *
     * @param activity_id 活动id
     * @return
     */
    @RequestMapping(value = "/delActivity")
    @ResponseBody
    public ResponseData delActivity(Long activity_id, @RequestParam(required = true) String admin_uuid) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            tenantPsychologicalAcvitityService.delPsychologicalAcvitity(activity_id);
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("删除活动失败!");
        }
        return reData;
    }

    /**
     * 修改活动
     *
     * @param activity_id   活动id
     * @param activity_type 活动类型 :心理讲座、团体活动、参加培训、参加案例督导、仪器设备使用、新闻上传、校区级公开课、其他活动
     * @param activity_date 活动日期
     * @return
     */
    @RequestMapping(value = "/updateActivity")
    @ResponseBody
    public ResponseData updateActivity(Long activity_id, String activity_type, String activity_date,
                                       Integer upload, String title, String contents, @RequestParam(required = true) String admin_uuid) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();

        TenantPsychologicalAcvitity tenantPsychologicalAcvitity = new TenantPsychologicalAcvitity();

        if (!StringUtils.isEmpty(activity_type)) {
            tenantPsychologicalAcvitity.setActivity_type(activity_type);
        }
        if (!StringUtils.isEmpty(activity_date)) {
            tenantPsychologicalAcvitity.setActivity_date(DateTimeUtil.getUtcFromString(activity_date));
        }
        if (upload != null) {
            tenantPsychologicalAcvitity.setUpload(upload);
        }
        if (!StringUtils.isEmpty(title)) {
            tenantPsychologicalAcvitity.setTitle(title);
        }
        if (!StringUtils.isEmpty(contents)) {
            tenantPsychologicalAcvitity.setContents(contents);
        }

        if (activity_id == null) {
            reData.setCode(-1);
            reData.setMsg("活动id不能为空!");
            return reData;
        }
        tenantPsychologicalAcvitity.setId(activity_id);
        try {
            tenantPsychologicalAcvitityService.updateByPrimaryKeySelective(tenantPsychologicalAcvitity);
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("修改活动失败!");
        }
        return reData;
    }

    /**
     * 获取活动
     *
     * @param activity_id
     * @return
     */
    @RequestMapping(value = "/getActivityByid")
    @ResponseBody
    public ResponseData getActivityByid(Long activity_id) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();

        if (activity_id == null) {
            reData.setCode(-1);
            reData.setMsg("活动id不能为空!");
            return reData;
        }
        try {
            Map<String, Object> mPsychologicalAcvitity = tenantPsychologicalAcvitityService.getPsychologicalAcvitityByid(activity_id);
            reData.setData(mPsychologicalAcvitity);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("修改活动失败!");
        }
        return reData;
    }

    /**
     * 获取活动列表
     *
     * @param
     * @param framework_id    单位id
     * @param psychologist_id 咨询师id
     * @param activity_type   活动类型
     * @param test_begin_date 活动日期
     * @param test_end_date   活动日期
     * @return
     */
    @RequestMapping(value = "/listActivity")
    @ResponseBody
    public ResponseData listActivity(Integer page, Integer page_size, Long framework_id, String psychologist_id, String activity_type,
                                     String test_begin_date, String test_end_date, String real_name, @RequestParam(required = true) String admin_uuid) {
        ResponseData mResponseData = new ResponseData();
        List<TenantPsychologicalAcvitity> mlist = new ArrayList();
        if (framework_id != null && framework_id == -1) {
            mResponseData.setCode(-1);
            mResponseData.setMsg("查询失败");
            return mResponseData;
        }
        AdminUser operator = getAdminUserInfoByUuid(admin_uuid);
        Map<String, Object> map = new HashMap<String, Object>();
        PageInfo pi = new PageInfo();
        if (!StringUtils.isEmpty(test_begin_date)) {
            map.put("test_begin_date", DateTimeUtil.getUtcFromString(test_begin_date));
        }
        if (!StringUtils.isEmpty(test_end_date)) {
            map.put("test_end_date", DateTimeUtil.getEndUtcFromString(test_end_date));
        }
//        getframeworkDatas(framework_id, operator, map);
        getTreePathDatas(framework_id, operator, map);
        if (!StringUtils.isEmpty(psychologist_id)) {
            map.put("psychologist_id", psychologist_id);
        }

        if (!StringUtils.isEmpty(activity_type))
            map.put("activity_type", activity_type);
        if (!StringUtils.isEmpty(real_name))
            map.put("real_name", real_name);
        if (page != null && page_size != null) {
            pi.setCurrentPage(page);
            pi.setPageSize(page_size);
        }
        try {
            List<Map<String, Object>> mPsychologicalAcvitity = tenantPsychologicalAcvitityService.listPsychologicalAcvitity(pi, map);
            long mCount = tenantPsychologicalAcvitityService.listPsychologicalAcvitityCount(map);
            map.clear();
            map.put("list", mPsychologicalAcvitity);
            map.put("mCount", mCount);
            mResponseData.setData(map);
        } catch (Exception e) {
            e.printStackTrace();
            mResponseData.setCode(-1);
            mResponseData.setMsg("查询失败");
            return mResponseData;
        }
        return mResponseData;
    }


    /**
     * 获取个案和咨询统计
     *
     * @param psychologist_id
     * @param framework_id
     * @param test_begin_date
     * @param test_end_date
     * @return
     */
    @RequestMapping(value = "/getCCStatistics")
    @ResponseBody
    public ResponseData getCaseAndCounselingStatistics(String psychologist_id, Long framework_id, String test_begin_date,
                                                       String test_end_date, @RequestParam(required = true) String admin_uuid) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        AdminUser operator = getAdminUserInfoByUuid(admin_uuid);
        if (!StringUtils.isEmpty(psychologist_id)) {
            map.put("psychologist_id", psychologist_id);
        }

        if (!StringUtils.isEmpty(test_begin_date)) {
            map.put("test_begin_date", DateTimeUtil.getUtcFromString(test_begin_date));
        }
        if (!StringUtils.isEmpty(test_end_date)) {
            map.put("test_end_date", DateTimeUtil.getEndUtcFromString(test_end_date));
        }
        getframeworkDatas(framework_id, operator, map);

        try {
            List<Map<String, Object>> mPsychologicalCounselingStatistics = tenantPsychologicalCounselingService
                    .getPsychologicalCounselingStatistics(map);
            List<Map<String, Object>> mPsychologicalCaseStatistics = tenantPsychologicalCaseService
                    .getPsychologicalCaseStatistics(map);
            map.put("mPsychologicalCounselingStatistics", mPsychologicalCounselingStatistics);
            map.put("PsychologicalCaseStatistics", mPsychologicalCaseStatistics);
            reData.setData(map);
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("获取信息失败!");
        }
        return reData;
    }

    /**
     * 获取活动统计
     *
     * @param psychologist_id
     * @param test_begin_date
     * @param test_end_date
     * @return
     */
    @RequestMapping(value = "/getActivitytatistics")
    @ResponseBody
    public ResponseData getActivitytatistics(String psychologist_id,
                                             Long framework_id, @RequestParam(required = true) String admin_uuid, String test_begin_date,
                                             String test_end_date) {
        ResponseData reData = new ResponseData();
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> retMap = new HashMap<>();
        AdminUser operator = getAdminUserInfoByUuid(admin_uuid);
//        getframeworkDatas(framework_id, operator, map);
        getTreePathDatas(framework_id, operator, map);

        if (!StringUtils.isEmpty(psychologist_id)) {
            map.put("psychologist_id", psychologist_id);
        }
        if (!StringUtils.isEmpty(test_begin_date)) {
            map.put("test_begin_date", DateTimeUtil.getUtcFromString(test_begin_date));
        }
        if (!StringUtils.isEmpty(test_end_date)) {
            map.put("test_end_date", DateTimeUtil.getEndUtcFromString(test_end_date));
        }
        try {
            List<Map<String, Object>> mPsychologicalAcvititystatistics = tenantPsychologicalAcvitityService
                    .getPsychologicalAcvititystatistics(map);
            retMap.put("mPsychologicalAcvititystatistics", mPsychologicalAcvititystatistics);
            reData.setData(retMap);
        } catch (Exception e) {
            log.error("getActivitytatistics exception", e);
            reData.setCode(-1);
            reData.setMsg("获取信息失败!");
        }
        return reData;
    }

    /**
     * 导出个案咨询统计表格
     *
     * @param request
     * @param response
     * @param psychologist_id
     * @param framework_id
     * @param test_begin_date
     * @param test_end_date
     * @param file_type       1 XLS 2 XLSX
     * @return
     * @throws IOException
     */
    @RequestMapping("/exCCStatistics")
    public void exCaseAndCounselingStatistics(HttpServletRequest request, HttpServletResponse response,
                                              String psychologist_id, Long framework_id, String test_begin_date, String test_end_date,
                                              @RequestParam(required = true) String admin_uuid, Integer file_type) throws IOException {
        String fileName = "个案咨询统计";
        response.setContentType("application/vnd.ms-excel;charset=utf-8");

        if (file_type == null || file_type == 1) {
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1"));
        } else {
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), "iso-8859-1"));
        }

        Map<String, Object> map = new HashMap<String, Object>();
        String timeStr = "~";
        if (!StringUtils.isEmpty(psychologist_id)) {
            map.put("psychologist_id", psychologist_id);
        }
        AdminUser operator = getAdminUserInfoByUuid(admin_uuid);
        getframeworkDatas(framework_id, operator, map);
        if (!StringUtils.isEmpty(test_begin_date)) {
            map.put("test_begin_date", DateTimeUtil.getUtcFromString(test_begin_date));
            timeStr = test_begin_date + timeStr;
        }
        if (!StringUtils.isEmpty(test_end_date)) {
            map.put("test_end_date", DateTimeUtil.getEndUtcFromString(test_end_date));
            timeStr = timeStr + test_end_date;
        }
        try {
            OutputStream os = response.getOutputStream();
            // 查询数据库中所有的数据
            List<Map<String, Object>> mPsychologicalCounselingStatistics = tenantPsychologicalCounselingService
                    .getPsychologicalCounselingStatistics(map);
            List<Map<String, Object>> mPsychologicalCaseStatistics = tenantPsychologicalCaseService
                    .getPsychologicalCaseStatistics(map);
            getExcelForCC(mPsychologicalCaseStatistics, mPsychologicalCounselingStatistics, os, timeStr);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return;
    }

    /**
     * 导出活动统计表格
     *
     * @param response
     * @param psychologist_id
     * @param framework_id
     * @param test_begin_date
     * @param test_end_date
     * @return
     * @throws IOException
     */
    @RequestMapping("/exActivitytatistics")
    public void exActivitytatistics(HttpServletResponse response, String psychologist_id,
                                    Long framework_id, String test_begin_date, String test_end_date,
                                    @RequestParam(required = true) String admin_uuid, Integer file_type) throws IOException {
        String fileName = "活动统计";
        String timeStr = "~";
        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        if (file_type == null || file_type == 1) {
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1"));
        } else {
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), "iso-8859-1"));
        }
        Map<String, Object> map = new HashMap<String, Object>();

        if (!StringUtils.isEmpty(psychologist_id)) {
            map.put("psychologist_id", psychologist_id);
        }
        AdminUser operator = getAdminUserInfoByUuid(admin_uuid);

        getframeworkDatas(framework_id, operator, map);

        if (!StringUtils.isEmpty(test_begin_date)) {
            map.put("test_begin_date", DateTimeUtil.getUtcFromString(test_begin_date));
            timeStr = test_begin_date + timeStr;
        }
        if (!StringUtils.isEmpty(test_end_date)) {
            map.put("test_end_date", DateTimeUtil.getEndUtcFromString(test_end_date));
            timeStr = timeStr + test_end_date;
        }
        try {
            OutputStream os = response.getOutputStream();

            // 查询数据库中所有的数据
            List<Map<String, Object>> mPsychologicalCounselingStatistics = tenantPsychologicalAcvitityService
                    .getPsychologicalAcvititystatistics(map);
            getExcelActivity(mPsychologicalCounselingStatistics, os, timeStr);

        } catch (Exception e) {
            e.printStackTrace();
        }
        // 日志

        return;
    }

    private void getExcelForCC(List<Map<String, Object>> listCases, List<Map<String, Object>> listCounselings, OutputStream os,
                               String timeStr) throws IOException, WriteException, RowsExceededException {
        WritableWorkbook wwb = null;
        // 创建可写入的Excel工作簿
        wwb = Workbook.createWorkbook(os);
        WritableSheet ws = wwb.createSheet("个案统计", 0);
        WritableSheet ws1 = wwb.createSheet("咨询类型统计", 1);
        WritableSheet ws2 = wwb.createSheet("咨询人员信息统计", 2);
        WritableSheet ws3 = wwb.createSheet("咨询方式统计", 3);
        WritableSheet ws4 = wwb.createSheet("设备类型", 4);
        // 查询数据库中所有的数据
        Map<String, Object> umap = new HashMap<String, Object>();

        List<Map<String, Object>> reportCases = listCases;
        List<Map<String, Object>> reportsCounseling = listCounselings;
        paintingForCC1(ws);
        paintingForCC(ws1);
        paintingForCC2(ws2);
        paintingForCC3(ws3);
        paintingForCC4(ws4);
        for (int i = 0; i < reportCases.size(); i++) {
            fillDataForCC1(ws, reportCases, i, timeStr);

        }

        for (int i = 0; i < reportsCounseling.size(); i++) {
            fillDataForCC(ws1, reportsCounseling, i, timeStr);
            fillDataForCC2(ws2, reportsCounseling, i, timeStr);
            fillDataForCC3(ws3, reportsCounseling, i, timeStr);
            fillDataForCC4(ws4, reportsCounseling, i, timeStr);


        }
        // 写进文档
        wwb.write();
        // 关闭Excel工作簿对象
        wwb.close();
    }

    private void getExcelActivity(List<Map<String, Object>> lists, OutputStream os, String timeStr)
            throws IOException, WriteException, RowsExceededException {
        WritableWorkbook wwb = null;
        // 创建可写入的Excel工作簿
        wwb = Workbook.createWorkbook(os);
        WritableSheet ws = wwb.createSheet("活动统计", 0);
        WritableSheet ws1 = wwb.createSheet("心理讲座统计", 1);
        WritableSheet ws2 = wwb.createSheet("团体活动统计", 2);
        WritableSheet ws3 = wwb.createSheet("参加培训统计", 3);
        WritableSheet ws4 = wwb.createSheet("参加案例督导统计", 4);
        WritableSheet ws5 = wwb.createSheet("承担公开课统计", 5);
        WritableSheet ws6 = wwb.createSheet("其他活动统计", 6);

        List<Map<String, Object>> reports = lists;

        paintingForActivity(ws);
        paintingForActivity1(ws1);
        paintingForActivity2(ws2);
        paintingForActivity3(ws3);
        paintingForActivity4(ws4);
        paintingForActivity5(ws5);
        paintingForActivity6(ws6);
        for (int i = 0; i < reports.size(); i++) {
            fillDataForActivity(ws, reports, i, timeStr);
            fillDataForActivity1(ws1, reports, i, timeStr);
            fillDataForActivity2(ws2, reports, i, timeStr);
            fillDataForActivity3(ws3, reports, i, timeStr);
            fillDataForActivity4(ws4, reports, i, timeStr);
            fillDataForActivity5(ws5, reports, i, timeStr);
            fillDataForActivity6(ws6, reports, i, timeStr);
        }
        // 写进文档
        wwb.write();
        // 关闭Excel工作簿对象
        wwb.close();
    }

    private void paintingForActivity4(WritableSheet ws3) throws WriteException, RowsExceededException {
        Label times3 = new Label(0, 0, "日期");
        Label tenant_name3 = new Label(1, 0, "学校名称");
        Label user_name3 = new Label(2, 0, "专业人员名称");
        Label aldd = new Label(3, 0, "案例督导次数");
        Label sjaldd = new Label(4, 0, "市级案例督导次数");
        Label qjaldd = new Label(5, 0, "区级案例督导次数");
        Label xjaldd = new Label(6, 0, "校级案例督导次数");

        ws3.addCell(times3);
        ws3.addCell(tenant_name3);
        ws3.addCell(user_name3);
        ws3.addCell(aldd);
        ws3.addCell(sjaldd);
        ws3.addCell(qjaldd);
        ws3.addCell(xjaldd);
    }

    private void paintingForActivity5(WritableSheet ws3) throws WriteException, RowsExceededException {
        Label times3 = new Label(0, 0, "日期");
        Label tenant_name3 = new Label(1, 0, "学校名称");
        Label user_name3 = new Label(2, 0, "专业人员名称");
        Label gkk = new Label(3, 0, "公开课总次数");
        Label sjgkk = new Label(4, 0, "市级公开课次数");
        Label qjgkk = new Label(5, 0, "区级公开课次数");
        Label xjgkk = new Label(6, 0, "校级公开课次数");

        ws3.addCell(times3);
        ws3.addCell(tenant_name3);
        ws3.addCell(user_name3);
        ws3.addCell(gkk);
        ws3.addCell(sjgkk);
        ws3.addCell(qjgkk);
        ws3.addCell(xjgkk);
    }

    private void paintingForActivity6(WritableSheet ws3) throws WriteException, RowsExceededException {
        Label times3 = new Label(0, 0, "日期");
        Label tenant_name3 = new Label(1, 0, "学校名称");
        Label user_name3 = new Label(2, 0, "专业人员名称");
        Label sbsy3 = new Label(3, 0, "其他活动总次数");
        Label fsy = new Label(4, 0, "市级其他活动次数");
        Label xxy = new Label(5, 0, "区级其他活动次数");
        Label rztj = new Label(6, 0, "校级其他活动次数");

        ws3.addCell(times3);
        ws3.addCell(tenant_name3);
        ws3.addCell(user_name3);
        ws3.addCell(sbsy3);
        ws3.addCell(fsy);
        ws3.addCell(xxy);
        ws3.addCell(rztj);
    }

    private void paintingForActivity3(WritableSheet ws3) throws WriteException, RowsExceededException {
        Label times3 = new Label(0, 0, "日期");
        Label tenant_name3 = new Label(1, 0, "学校名称");
        Label user_name3 = new Label(2, 0, "专业人员名称");
        Label cjpx = new Label(3, 0, "培训总次数");
        Label cjsjpx = new Label(4, 0, "市级培训次数");
        Label cjqjpx = new Label(5, 0, "区级培训次数");
        Label cjxjpx = new Label(6, 0, "校级培训次数");


        ws3.addCell(times3);
        ws3.addCell(tenant_name3);
        ws3.addCell(user_name3);
        ws3.addCell(cjpx);
        ws3.addCell(cjsjpx);
        ws3.addCell(cjqjpx);
        ws3.addCell(cjxjpx);
    }

    private void paintingForActivity2(WritableSheet ws2) throws WriteException, RowsExceededException {
        Label times2 = new Label(0, 0, "日期");
        Label tenant_name2 = new Label(1, 0, "学校名称");
        Label user_name2 = new Label(2, 0, "专业人员名称");
        Label tthdzcs2 = new Label(3, 0, "团体活动总次数");
        Label sthd = new Label(4, 0, "社团活动次数");
        Label xltz = new Label(5, 0, "心理拓展课探究课次数");
        Label xlhd = new Label(6, 0, "心理活动月活动次数");
        Label ttfd = new Label(7, 0, "团体辅导活动次数");
        Label attthd = new Label(8, 0, "其他活动次数");

        ws2.addCell(times2);
        ws2.addCell(tenant_name2);
        ws2.addCell(user_name2);
        ws2.addCell(tthdzcs2);
        ws2.addCell(sthd);
        ws2.addCell(xltz);
        ws2.addCell(xlhd);
        ws2.addCell(ttfd);
        ws2.addCell(attthd);
    }

    private void paintingForActivity1(WritableSheet ws1) throws WriteException, RowsExceededException {
        // 要插入到的Excel表格的行号，默认从0开始
        Label times1 = new Label(0, 0, "日期");
        Label tenant_name1 = new Label(1, 0, "学校名称");
        Label user_name1 = new Label(2, 0, "专业人员名称");
        Label jzzcs1 = new Label(3, 0, "心理讲座总次数");
        Label xsjz = new Label(4, 0, "学生讲座次数");
        Label jsjz = new Label(5, 0, "教师讲座次数");
        Label jzjz = new Label(6, 0, "家长讲座次数");
        Label qtjz = new Label(7, 0, "其他对象讲座次数");
        Label sjjz = new Label(8, 0, "市级公开讲座");
        Label qjjz = new Label(9, 0, "区级公开讲座");
        Label xjjz = new Label(10, 0, "校级公开讲座");

        ws1.addCell(times1);
        ws1.addCell(tenant_name1);
        ws1.addCell(user_name1);
        ws1.addCell(jzzcs1);
        ws1.addCell(xsjz);
        ws1.addCell(jsjz);
        ws1.addCell(jzjz);
        ws1.addCell(qtjz);
        ws1.addCell(sjjz);
        ws1.addCell(qjjz);
        ws1.addCell(xjjz);
    }

    private void paintingForActivity(WritableSheet ws) throws WriteException, RowsExceededException {
        Label times0 = new Label(0, 0, "日期");
        Label tenant_name0 = new Label(1, 0, "学校名称");
        Label user_name0 = new Label(2, 0, "专业人员名称");
        Label jzzcs = new Label(3, 0, "心理讲座总次数");
        Label tthdzcs = new Label(4, 0, "团体活动总次数");
        Label cjpx = new Label(5, 0, "参加培训总次数");
        Label aldd = new Label(6, 0, "参加案例督导总次数");
        Label gkk = new Label(7, 0, "承担公开课总次数");
        Label qthd = new Label(8, 0, "其他活动总次数");
        Label kczy = new Label(9, 0, "课程资源总次数");
        Label yjcg = new Label(10, 0, "研究成果总次数");

        ws.addCell(times0);
        ws.addCell(tenant_name0);
        ws.addCell(user_name0);
        ws.addCell(jzzcs);
        ws.addCell(tthdzcs);
        ws.addCell(cjpx);
        ws.addCell(aldd);
        ws.addCell(gkk);
        ws.addCell(qthd);
        ws.addCell(kczy);
        ws.addCell(yjcg);
    }

    private void fillDataForActivity4(WritableSheet ws3, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times3_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name3_i = getData(1, reports, i, "tenant_name");
        Label user_name3_i = getData(2, reports, i, "user_name");
        Label aldd_i = getData(3, reports, i, "aldd");
        Label sjaldd_i = getData(4, reports, i, "sjaldd");
        Label qjaldd_i = getData(5, reports, i, "qjaldd");
        Label xjaldd_i = getData(6, reports, i, "xjaldd");

        ws3.addCell(times3_i);
        ws3.addCell(tenant_name3_i);
        ws3.addCell(user_name3_i);
        ws3.addCell(aldd_i);
        ws3.addCell(sjaldd_i);
        ws3.addCell(qjaldd_i);
        ws3.addCell(xjaldd_i);

        if (i == reports.size() - 1) {
            int aldd_t = 0;
            int sjaldd_t = 0;
            int qjaldd_t = 0;
            int xjaldd_t = 0;
            for (int j = 0; j < reports.size(); j++) {
                aldd_t += getCount(reports, j, "aldd");
                sjaldd_t += getCount(reports, j, "sjaldd");
                qjaldd_t += getCount(reports, j, "qjaldd");
                xjaldd_t += getCount(reports, j, "xjaldd");
            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label aldd_i_t = getData(3, reports, i + 1, "aldd", aldd_t + "");
            Label sjaldd_i_t = getData(4, reports, i + 1, "sjaldd", sjaldd_t + "");
            Label qjaldd_i_t = getData(5, reports, i + 1, "qjaldd", qjaldd_t + "");
            Label xjaldd_i_t = getData(6, reports, i + 1, "xjaldd", xjaldd_t + "");

            ws3.addCell(times0_i_t);
            ws3.addCell(aldd_i_t);
            ws3.addCell(sjaldd_i_t);
            ws3.addCell(qjaldd_i_t);
            ws3.addCell(xjaldd_i_t);
        }

    }

    private void fillDataForActivity5(WritableSheet ws3, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times3_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name3_i = getData(1, reports, i, "tenant_name");
        Label user_name3_i = getData(2, reports, i, "user_name");
        Label sbsy3_i = getData(3, reports, i, "gkk");
        Label fsy_i = getData(4, reports, i, "sjgkk");
        Label xxy_i = getData(5, reports, i, "qjgkk");
        Label rztj_i = getData(6, reports, i, "xjgkk");

        ws3.addCell(times3_i);
        ws3.addCell(tenant_name3_i);
        ws3.addCell(user_name3_i);
        ws3.addCell(sbsy3_i);
        ws3.addCell(fsy_i);
        ws3.addCell(xxy_i);
        ws3.addCell(rztj_i);

        if (i == reports.size() - 1) {
            int sbsy_t = 0;
            int fsy_t = 0;
            int xxy_t = 0;
            int rztj_t = 0;
            for (int j = 0; j < reports.size(); j++) {
                sbsy_t += getCount(reports, j, "gkk");
                fsy_t += getCount(reports, j, "sjgkk");
                xxy_t += getCount(reports, j, "qjgkk");
                rztj_t += getCount(reports, j, "xjgkk");
            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label sbsy_i_t = getData(3, reports, i + 1, "gkk", sbsy_t + "");
            Label fsy_i_t = getData(4, reports, i + 1, "sjgkk", fsy_t + "");
            Label xxy_i_t = getData(5, reports, i + 1, "qjgkk", xxy_t + "");
            Label jrztj_i_t = getData(6, reports, i + 1, "xjgkk", rztj_t + "");

            ws3.addCell(times0_i_t);
            ws3.addCell(sbsy_i_t);
            ws3.addCell(fsy_i_t);
            ws3.addCell(xxy_i_t);
            ws3.addCell(jrztj_i_t);
        }

    }

    private void fillDataForActivity6(WritableSheet ws3, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times3_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name3_i = getData(1, reports, i, "tenant_name");
        Label user_name3_i = getData(2, reports, i, "user_name");
        Label sbsy3_i = getData(3, reports, i, "qthd");
        Label fsy_i = getData(4, reports, i, "sjqthd");
        Label xxy_i = getData(5, reports, i, "qjqthd");
        Label rztj_i = getData(6, reports, i, "xjqthd");

        ws3.addCell(times3_i);
        ws3.addCell(tenant_name3_i);
        ws3.addCell(user_name3_i);
        ws3.addCell(sbsy3_i);
        ws3.addCell(fsy_i);
        ws3.addCell(xxy_i);
        ws3.addCell(rztj_i);

        if (i == reports.size() - 1) {
            int sbsy_t = 0;
            int fsy_t = 0;
            int xxy_t = 0;
            int rztj_t = 0;
            int jjxl_t = 0;
            int qtxl_t = 0;
            for (int j = 0; j < reports.size(); j++) {
                sbsy_t += getCount(reports, j, "qthd");
                fsy_t += getCount(reports, j, "sjqthd");
                xxy_t += getCount(reports, j, "qjqthd");
                rztj_t += getCount(reports, j, "xjqthd");
            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label sbsy_i_t = getData(3, reports, i + 1, "qthd", sbsy_t + "");
            Label fsy_i_t = getData(4, reports, i + 1, "sjqthd", fsy_t + "");
            Label xxy_i_t = getData(5, reports, i + 1, "qjqthd", xxy_t + "");
            Label jrztj_i_t = getData(6, reports, i + 1, "xjqthd", rztj_t + "");

            ws3.addCell(times0_i_t);
            ws3.addCell(sbsy_i_t);
            ws3.addCell(fsy_i_t);
            ws3.addCell(xxy_i_t);
            ws3.addCell(jrztj_i_t);
        }

    }

    private void fillDataForActivity3(WritableSheet ws3, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times3_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name3_i = getData(1, reports, i, "tenant_name");
        Label user_name3_i = getData(2, reports, i, "user_name");
        Label sbsy3_i = getData(3, reports, i, "cjpx");
        Label fsy_i = getData(4, reports, i, "cjsjpx");
        Label xxy_i = getData(5, reports, i, "cjqjpx");
        Label rztj_i = getData(6, reports, i, "cjxjpx");

        ws3.addCell(times3_i);
        ws3.addCell(tenant_name3_i);
        ws3.addCell(user_name3_i);
        ws3.addCell(sbsy3_i);
        ws3.addCell(fsy_i);
        ws3.addCell(xxy_i);
        ws3.addCell(rztj_i);

        if (i == reports.size() - 1) {
            int sbsy_t = 0;
            int fsy_t = 0;
            int xxy_t = 0;
            int rztj_t = 0;
            int jjxl_t = 0;
            int qtxl_t = 0;
            for (int j = 0; j < reports.size(); j++) {
                sbsy_t += getCount(reports, j, "cjpx");
                fsy_t += getCount(reports, j, "cjsjpx");
                xxy_t += getCount(reports, j, "cjqjpx");
                rztj_t += getCount(reports, j, "cjxjpx");
            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label sbsy_i_t = getData(3, reports, i + 1, "cjpx", sbsy_t + "");
            Label fsy_i_t = getData(4, reports, i + 1, "cjsjpx", fsy_t + "");
            Label xxy_i_t = getData(5, reports, i + 1, "cjqjpx", xxy_t + "");
            Label jrztj_i_t = getData(6, reports, i + 1, "cjxjpx", rztj_t + "");

            ws3.addCell(times0_i_t);
            ws3.addCell(sbsy_i_t);
            ws3.addCell(fsy_i_t);
            ws3.addCell(xxy_i_t);
            ws3.addCell(jrztj_i_t);
        }

    }

    private void fillDataForActivity2(WritableSheet ws2, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times2_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name2_i = getData(1, reports, i, "tenant_name");
        Label user_name2_i = getData(2, reports, i, "user_name");
        Label tthdzcs_i = getData(3, reports, i, "tthdzcs");
        Label sthd_i = getData(4, reports, i, "sthd");
        Label xltz_i = getData(5, reports, i, "xltz");
        Label xlhd_i = getData(6, reports, i, "xlhd");
        Label ttfd_i = getData(7, reports, i, "ttfd");
        Label attthd_i = getData(8, reports, i, "attthd");

        ws2.addCell(times2_i);
        ws2.addCell(tenant_name2_i);
        ws2.addCell(user_name2_i);
        ws2.addCell(tthdzcs_i);
        ws2.addCell(sthd_i);
        ws2.addCell(xltz_i);
        ws2.addCell(xlhd_i);
        ws2.addCell(ttfd_i);
        ws2.addCell(attthd_i);

        if (i == reports.size() - 1) {
            int tthdzcs_t = 0;
            int sthd_t = 0;
            int xltz_t = 0;
            int xlhd_t = 0;
            int ttfd_t = 0;
            int attthd_t = 0;
            for (int j = 0; j < reports.size(); j++) {
                tthdzcs_t += getCount(reports, j, "tthdzcs");
                sthd_t += getCount(reports, j, "sthd");
                xltz_t += getCount(reports, j, "xltz");
                xlhd_t += getCount(reports, j, "xlhd");
                ttfd_t += getCount(reports, j, "ttfd");
                attthd_t += getCount(reports, j, "attthd");
            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label tthdzcs_i_t = getData(3, reports, i + 1, "tthdzcs", tthdzcs_t + "");
            Label sthd_i_t = getData(4, reports, i + 1, "sthd", sthd_t + "");
            Label xltz_i_t = getData(5, reports, i + 1, "xltz", xltz_t + "");
            Label xlhd_i_t = getData(6, reports, i + 1, "xlhd", xlhd_t + "");
            Label ttfd_i_t = getData(7, reports, i + 1, "ttfd", ttfd_t + "");
            Label attthd_i_t = getData(8, reports, i + 1, "attthd", attthd_t + "");

            ws2.addCell(times0_i_t);
            ws2.addCell(tthdzcs_i_t);
            ws2.addCell(sthd_i_t);
            ws2.addCell(xltz_i_t);
            ws2.addCell(xlhd_i_t);
            ws2.addCell(ttfd_i_t);
            ws2.addCell(attthd_i_t);
        }
    }

    private void fillDataForActivity1(WritableSheet ws1, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times1_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name1_i = getData(1, reports, i, "tenant_name");
        Label user_name1_i = getData(2, reports, i, "user_name");
        Label jzzcs1_i = getData(3, reports, i, "jzzcs");
        Label xsjz_i = getData(4, reports, i, "xsjz");
        Label jsjz_i = getData(5, reports, i, "jsjz");
        Label jzjz_i = getData(6, reports, i, "jzjz");
        Label qtjz_i = getData(7, reports, i, "qtjz");
        Label sjjz_i = getData(8, reports, i, "sjjz");
        Label qjjz_i = getData(9, reports, i, "qjjz");
        Label xjjz_i = getData(10, reports, i, "xjjz");

        ws1.addCell(times1_i);
        ws1.addCell(tenant_name1_i);
        ws1.addCell(user_name1_i);
        ws1.addCell(jzzcs1_i);
        ws1.addCell(xsjz_i);
        ws1.addCell(jsjz_i);
        ws1.addCell(jzjz_i);
        ws1.addCell(qtjz_i);
        ws1.addCell(sjjz_i);
        ws1.addCell(qjjz_i);
        ws1.addCell(xjjz_i);

        if (i == reports.size() - 1) {
            int jzzcs_t = 0;
            int xsjz_t = 0;
            int jsjz_t = 0;
            int jzjz_t = 0;
            int qtjz_t = 0;
            int sjjz_t = 0;
            int qjjz_t = 0;
            int xjjz_t = 0;
            for (int j = 0; j < reports.size(); j++) {
                jzzcs_t += getCount(reports, j, "jzzcs");
                xsjz_t += getCount(reports, j, "xsjz");
                jsjz_t += getCount(reports, j, "jsjz");
                jzjz_t += getCount(reports, j, "jzjz");
                qtjz_t += getCount(reports, j, "qtjz");
                sjjz_t += getCount(reports, j, "sjjz");
                qjjz_t += getCount(reports, j, "qjjz");
                xjjz_t += getCount(reports, j, "xjjz");
            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label jzzcs_i_t = getData(3, reports, i + 1, "jzzcs", jzzcs_t + "");
            Label xsjz_i_t = getData(4, reports, i + 1, "xsjz", xsjz_t + "");
            Label jsjz_i_t = getData(5, reports, i + 1, "jsjz", jsjz_t + "");
            Label jzjz_i_t = getData(6, reports, i + 1, "jzjz", jzjz_t + "");
            Label qtjz_i_t = getData(7, reports, i + 1, "qtjz", qtjz_t + "");
            Label sjjz_i_t = getData(8, reports, i + 1, "sjjz", sjjz_t + "");
            Label qjjz_i_t = getData(9, reports, i + 1, "qjjz", qjjz_t + "");
            Label xjjz_i_t = getData(10, reports, i + 1, "xjjz", xjjz_t + "");

            ws1.addCell(times0_i_t);
            ws1.addCell(jzzcs_i_t);
            ws1.addCell(xsjz_i_t);
            ws1.addCell(jsjz_i_t);
            ws1.addCell(jzjz_i_t);
            ws1.addCell(qtjz_i_t);
            ws1.addCell(sjjz_i_t);
            ws1.addCell(qjjz_i_t);
            ws1.addCell(xjjz_i_t);
        }

    }

    private void fillDataForActivity(WritableSheet ws, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {

        Label times0_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name0_i = getData(1, reports, i, "tenant_name");
        Label user_name0_i = getData(2, reports, i, "user_name");
        Label jzzcs_i = getData(3, reports, i, "jzzcs");
        Label tthdzcs_i = getData(4, reports, i, "tthdzcs");
        Label cjpx_i = getData(5, reports, i, "cjpx");
        Label aldd_i = getData(6, reports, i, "aldd");
        Label gkk_i = getData(7, reports, i, "gkk");
        Label qthd_i = getData(8, reports, i, "qthd");
        Label kczy_i = getData(9, reports, i, "kczy");
        Label yjcg_i = getData(10, reports, i, "yjcg");
        ws.addCell(times0_i);
        ws.addCell(tenant_name0_i);
        ws.addCell(user_name0_i);
        ws.addCell(jzzcs_i);
        ws.addCell(tthdzcs_i);
        ws.addCell(cjpx_i);
        ws.addCell(aldd_i);
        ws.addCell(gkk_i);
        ws.addCell(qthd_i);
        ws.addCell(kczy_i);
        ws.addCell(yjcg_i);
        if (i == reports.size() - 1) {
            int jzzcs_t = 0;
            int tthdzcs_t = 0;
            int cjpx_t = 0;
            int aldd_t = 0;
            int gkk_t = 0;
            int qthd_t = 0;
            int kczy_t = 0;
            int yjcg_t = 0;
            for (int j = 0; j < reports.size(); j++) {
                jzzcs_t += getCount(reports, j, "jzzcs");
                tthdzcs_t += getCount(reports, j, "tthdzcs");
                cjpx_t += getCount(reports, j, "cjpx");
                aldd_t += getCount(reports, j, "aldd");
                gkk_t += getCount(reports, j, "gkk");
                qthd_t += getCount(reports, j, "qthd");
                kczy_t += getCount(reports, j, "kczy");
                yjcg_t += getCount(reports, j, "yjcg");
            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label jzzcs_i_t = getData(3, reports, i + 1, "jzzcs", jzzcs_t + "");
            Label tthdzcs_i_t = getData(4, reports, i + 1, "tthdzcs", tthdzcs_t + "");
            Label cjpx_i_t = getData(5, reports, i + 1, "cjpx", cjpx_t + "");
            Label aldd_i_t = getData(6, reports, i + 1, "aldd", aldd_t + "");
            Label gkk_i_t = getData(7, reports, i + 1, "gkk", gkk_t + "");
            Label qthd_i_t = getData(8, reports, i + 1, "qthd", qthd_t + "");
            Label kczy_i_t = getData(9, reports, i + 1, "kczy", kczy_t + "");
            Label yjcg_i_t = getData(10, reports, i + 1, "yjcg", yjcg_t + "");

            ws.addCell(times0_i_t);
            ws.addCell(jzzcs_i_t);
            ws.addCell(tthdzcs_i_t);
            ws.addCell(cjpx_i_t);
            ws.addCell(aldd_i_t);
            ws.addCell(gkk_i_t);
            ws.addCell(qthd_i_t);
            ws.addCell(kczy_i_t);
            ws.addCell(yjcg_i_t);
        }
    }

    private void fillDataForCC2(WritableSheet ws2, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times2_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name2_i = getData(1, reports, i, "tenant_name");
        Label user_name2_i = getData(2, reports, i, "user_name");
        Label case_counts2_i = getData(3, reports, i, "coun_counts");
        Label identity_xs_i = getData(4, reports, i, "identity_xs");
        Label identity_fm_i = getData(5, reports, i, "identity_fm");
        Label identity_ls_i = getData(6, reports, i, "identity_ls");
        Label identity_qt_i = getData(7, reports, i, "identity_qt");

        ws2.addCell(times2_i);
        ws2.addCell(tenant_name2_i);
        ws2.addCell(user_name2_i);
        ws2.addCell(case_counts2_i);
        ws2.addCell(identity_xs_i);
        ws2.addCell(identity_fm_i);
        ws2.addCell(identity_ls_i);
        ws2.addCell(identity_qt_i);

        if (i == reports.size() - 1) {
            int case_counts_t = 0;
            int man_t = 0;
            int women_t = 0;
            int xx_t = 0;
            int cz_t = 0;
            int gz_t = 0;
            int yey_t = 0;
            int identity_xs_t = 0;
            int identity_fm_t = 0;
            int identity_ls_t = 0;
            int identity_qt_t = 0;

            for (int j = 0; j < reports.size(); j++) {
                case_counts_t += getCount(reports, j, "coun_counts");
                identity_xs_t += getCount(reports, j, "identity_xs");
                identity_fm_t += getCount(reports, j, "identity_fm");
                identity_ls_t += getCount(reports, j, "identity_ls");
                identity_qt_t += getCount(reports, j, "identity_qt");

            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label case_counts_i_t = getData(3, reports, i + 1, "coun_counts", case_counts_t + "");
            Label identity_xs_i_t = getData(4, reports, i + 1, "identity_xs", identity_xs_t + "");
            Label identity_fm_i_t = getData(5, reports, i + 1, "identity_fm", identity_fm_t + "");
            Label identity_ls_i_t = getData(6, reports, i + 1, "identity_ls", identity_ls_t + "");
            Label identity_qt_i_t = getData(7, reports, i + 1, "identity_qt", identity_qt_t + "");

            ws2.addCell(times0_i_t);
            ws2.addCell(case_counts_i_t);
            ws2.addCell(identity_xs_i_t);
            ws2.addCell(identity_fm_i_t);
            ws2.addCell(identity_ls_i_t);
            ws2.addCell(identity_qt_i_t);
        }

    }

    private void fillDataForCC1(WritableSheet ws2, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times2_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name2_i = getData(1, reports, i, "tenant_name");
        Label user_name2_i = getData(2, reports, i, "user_name");
        Label case_counts2_i = getData(3, reports, i, "case_counts");
        Label man_i = getData(4, reports, i, "man");
        Label women_i = getData(5, reports, i, "women");
        Label xx_i = getData(6, reports, i, "xx");
        Label cz_i = getData(7, reports, i, "cz");
        Label gz_i = getData(8, reports, i, "gz");
        Label yey_i = getData(9, reports, i, "yey");
        Label university_i = getData(10, reports, i, "university");
        Label teenager_i = getData(11, reports, i, "teenager");
        Label middleage_i = getData(12, reports, i, "middleage");
        Label oldage_i = getData(13, reports, i, "oldage");

        ws2.addCell(times2_i);
        ws2.addCell(tenant_name2_i);
        ws2.addCell(user_name2_i);
        ws2.addCell(case_counts2_i);
        ws2.addCell(man_i);
        ws2.addCell(women_i);
        ws2.addCell(xx_i);
        ws2.addCell(cz_i);
        ws2.addCell(gz_i);
        ws2.addCell(yey_i);
        ws2.addCell(university_i);
        ws2.addCell(teenager_i);
        ws2.addCell(middleage_i);
        ws2.addCell(oldage_i);

        if (i == reports.size() - 1) {
            int case_counts_t = 0;
            int man_t = 0;
            int women_t = 0;
            int xx_t = 0;
            int cz_t = 0;
            int gz_t = 0;
            int yey_t = 0;
            int university_t = 0;
            int teenager_t = 0;
            int middleage_t = 0;
            int oldage_t = 0;

            for (int j = 0; j < reports.size(); j++) {
                case_counts_t += getCount(reports, j, "case_counts");
                man_t += getCount(reports, j, "man");
                women_t += getCount(reports, j, "women");
                xx_t += getCount(reports, j, "xx");
                cz_t += getCount(reports, j, "cz");
                gz_t += getCount(reports, j, "gz");
                yey_t += getCount(reports, j, "yey");
                university_t += getCount(reports, j, "university");
                teenager_t += getCount(reports, j, "teenager");
                middleage_t += getCount(reports, j, "middleage");
                oldage_t += getCount(reports, j, "oldage");

            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label case_counts_i_t = getData(3, reports, i + 1, "case_counts", case_counts_t + "");
            Label man_i_t = getData(4, reports, i + 1, "man", man_t + "");
            Label women_i_t = getData(5, reports, i + 1, "women", women_t + "");
            Label xx_i_t = getData(6, reports, i + 1, "xx", xx_t + "");
            Label cz_i_t = getData(7, reports, i + 1, "cz", cz_t + "");
            Label gz_i_t = getData(8, reports, i + 1, "gz", gz_t + "");
            Label yey_i_t = getData(9, reports, i + 1, " yey", yey_t + "");
            Label university_i_t = getData(10, reports, i + 1, "university", university_t + "");
            Label teenager_i_t = getData(11, reports, i + 1, "teenager", teenager_t + "");
            Label middleage_i_t = getData(12, reports, i + 1, "middleage", middleage_t + "");
            Label oldage_i_t = getData(13, reports, i + 1, "oldage", oldage_t + "");

            ws2.addCell(times0_i_t);
            ws2.addCell(case_counts_i_t);
            ws2.addCell(man_i_t);
            ws2.addCell(women_i_t);
            ws2.addCell(xx_i_t);
            ws2.addCell(cz_i_t);
            ws2.addCell(gz_i_t);
            ws2.addCell(yey_i_t);
            ws2.addCell(university_i_t);
            ws2.addCell(teenager_i_t);
            ws2.addCell(middleage_i_t);
            ws2.addCell(oldage_i_t);
        }
    }

    private void fillDataForCC(WritableSheet ws, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name_i = getData(1, reports, i, "tenant_name");
        Label user_name_i = getData(2, reports, i, "user_name");
        Label case_counts_i = getData(3, reports, i, "case_counts");
        Label yqyq_i = getData(4, reports, i, "yqyq");
        Label xywt_i = getData(5, reports, i, "xywt");
        Label ywwt_i = getData(6, reports, i, "ywwt");
        Label qxet_i = getData(7, reports, i, "qxet");
        Label jsjb_i = getData(8, reports, i, "jsjb");
        Label qcq_i = getData(9, reports, i, "qcq");
        Label tbjw_i = getData(10, reports, i, "tbjw");
        Label ssgx_i = getData(11, reports, i, "ssgx");
        Label sjwl_i = getData(12, reports, i, "sjwl");
        Label sxzx_i = getData(13, reports, i, "sxzx");
        Label jthj_i = getData(14, reports, i, "jthj");
        Label qzgx_i = getData(15, reports, i, "qzgx");
        Label xlwj_i = getData(16, reports, i, "xlwj");
        Label hf_i = getData(17, reports, i, "hf");
        Label qt_i = getData(18, reports, i, "qt");

        ws.addCell(times_i);
        ws.addCell(tenant_name_i);
        ws.addCell(user_name_i);
        ws.addCell(case_counts_i);
        ws.addCell(yqyq_i);
        ws.addCell(xywt_i);
        ws.addCell(ywwt_i);
        ws.addCell(qxet_i);
        ws.addCell(jsjb_i);
        ws.addCell(qcq_i);
        ws.addCell(tbjw_i);
        ws.addCell(ssgx_i);
        ws.addCell(sjwl_i);
        ws.addCell(sxzx_i);
        ws.addCell(jthj_i);
        ws.addCell(qzgx_i);
        ws.addCell(xlwj_i);
        ws.addCell(hf_i);
        ws.addCell(qt_i);

        if (i == reports.size() - 1) {
            int case_counts_t = 0;
            int yqyq_t = 0;
            int xywt_t = 0;
            int ywwt_t = 0;
            int qxet_t = 0;
            int jsjb_t = 0;
            int qcq_t = 0;
            int tbjw_t = 0;
            int ssgx_t = 0;
            int sjwl_t = 0;
            int sxzx_t = 0;
            int jthj_t = 0;
            int qzgx_t = 0;
            int xlwj_t = 0;
            int hf_t = 0;
            int qt_t = 0;
            for (int j = 0; j < reports.size(); j++) {
                case_counts_t += getCount(reports, j, "case_counts");
                yqyq_t += getCount(reports, j, "yqyq");
                xywt_t += getCount(reports, j, "xywt");
                ywwt_t += getCount(reports, j, "ywwt");
                qxet_t += getCount(reports, j, "qxet");
                jsjb_t += getCount(reports, j, "jsjb");
                qcq_t += getCount(reports, j, "qcq");
                tbjw_t += getCount(reports, j, "tbjw");
                ssgx_t += getCount(reports, j, "ssgx");
                sjwl_t += getCount(reports, j, "sjwl");
                sxzx_t += getCount(reports, j, "sxzx");
                jthj_t += getCount(reports, j, "jthj");
                qzgx_t += getCount(reports, j, "qzgx");
                xlwj_t += getCount(reports, j, "xlwj");
                hf_t += getCount(reports, j, "hf");
                qt_t += getCount(reports, j, "qt");

            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label case_counts_i_t = getData(3, reports, i + 1, "case_counts", case_counts_t + "");
            Label yqyq_i_t = getData(4, reports, i + 1, "yqyq", yqyq_t + "");
            Label xywt_i_t = getData(5, reports, i + 1, "xywt", xywt_t + "");
            Label ywwt_i_t = getData(6, reports, i + 1, "ywwt", ywwt_t + "");
            Label qxet_i_t = getData(7, reports, i + 1, "qxet", qxet_t + "");
            Label jsjb_i_t = getData(8, reports, i + 1, "jsjb", jsjb_t + "");
            Label qcq_i_t = getData(9, reports, i + 1, "qcq", qcq_t + "");
            Label tbjw_i_t = getData(10, reports, i + 1, "tbjw", tbjw_t + "");
            Label ssgx_i_t = getData(11, reports, i + 1, "ssgx", ssgx_t + "");
            Label sjwl_i_t = getData(12, reports, i + 1, "sjwl", sjwl_t + "");
            Label sxzx_i_t = getData(13, reports, i + 1, "sxzx", sxzx_t + "");
            Label jthj_i_t = getData(14, reports, i + 1, "jthj", jthj_t + "");
            Label qzgx_i_t = getData(15, reports, i + 1, "qzgx", qzgx_t + "");
            Label xlwj_i_t = getData(16, reports, i + 1, "xlwj", xlwj_t + "");
            Label hf_i_t = getData(17, reports, i + 1, "hf", hf_t + "");
            Label qt_i_t = getData(18, reports, i + 1, "qt", qt_t + "");

            ws.addCell(times0_i_t);
            ws.addCell(case_counts_i_t);
            ws.addCell(yqyq_i_t);
            ws.addCell(xywt_i_t);
            ws.addCell(ywwt_i_t);
            ws.addCell(qxet_i_t);
            ws.addCell(jsjb_i_t);
            ws.addCell(qcq_i_t);
            ws.addCell(tbjw_i_t);
            ws.addCell(ssgx_i_t);
            ws.addCell(sjwl_i_t);
            ws.addCell(sxzx_i_t);
            ws.addCell(jthj_i_t);
            ws.addCell(qzgx_i_t);
            ws.addCell(xlwj_i_t);
            ws.addCell(hf_i_t);
            ws.addCell(qt_i_t);

        }

    }

    private void fillDataForCC3(WritableSheet ws3, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times3_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name3_i = getData(1, reports, i, "tenant_name");
        Label user_name3_i = getData(2, reports, i, "user_name");
        Label coun_counts_i = getData(3, reports, i, "coun_counts");
        Label cmx_i = getData(4, reports, i, "cmx");
        Label csp_i = getData(5, reports, i, "csp");
        Label cyy_i = getData(6, reports, i, "cyy");
        Label cwz_i = getData(7, reports, i, "cwz");
        Label cqt_i = getData(8, reports, i, "cqt");

        ws3.addCell(times3_i);
        ws3.addCell(tenant_name3_i);
        ws3.addCell(user_name3_i);
        ws3.addCell(coun_counts_i);
        ws3.addCell(cmx_i);
        ws3.addCell(csp_i);
        ws3.addCell(cyy_i);
        ws3.addCell(cwz_i);
        ws3.addCell(cqt_i);

        if (i == reports.size() - 1) {
            int coun_counts_t = 0;
            int cmx_t = 0;
            int csp_t = 0;
            int cyy_t = 0;
            int cwz_t = 0;
            int cqt_t = 0;
            for (int j = 0; j < reports.size(); j++) {
                coun_counts_t += getCount(reports, j, "coun_counts");
                cmx_t += getCount(reports, j, "cmx");
                csp_t += getCount(reports, j, "csp");
                cyy_t += getCount(reports, j, "cyy");
                cwz_t += getCount(reports, j, "cwz");
                cqt_t += getCount(reports, j, "cqt");
            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label coun_counts_i_t = getData(3, reports, i + 1, "coun_counts", coun_counts_t + "");
            Label cmx_i_t = getData(4, reports, i + 1, "cmx", cmx_t + "");
            Label csp_i_t = getData(5, reports, i + 1, "csp", csp_t + "");
            Label cyy_i_t = getData(6, reports, i + 1, "cyy", cyy_t + "");
            Label cwz_i_t = getData(7, reports, i + 1, "cwz", cwz_t + "");
            Label cqt_i_t = getData(8, reports, i + 1, "cqt", cqt_t + "");

            ws3.addCell(times0_i_t);
            ws3.addCell(coun_counts_i_t);
            ws3.addCell(cmx_i_t);
            ws3.addCell(csp_i_t);
            ws3.addCell(cyy_i_t);
            ws3.addCell(cwz_i_t);
            ws3.addCell(cqt_i_t);
        }

    }

    private void fillDataForCC4(WritableSheet ws4, List<Map<String, Object>> reports, int i, String timeStr)
            throws WriteException, RowsExceededException {
        Label times3_i = getData(0, reports, i, "times", timeStr);
        Label tenant_name3_i = getData(1, reports, i, "tenant_name");
        Label user_name3_i = getData(2, reports, i, "user_name");
        Label coun_counts_i = getData(3, reports, i, "coun_counts");
        Label fsy_i = getData(4, reports, i, "fsy");
        Label xxy_i = getData(5, reports, i, "xxy");
        Label rztj_i = getData(6, reports, i, "rztj");
        Label xltj_i = getData(7, reports, i, "xltj");
        Label qtyq_i = getData(8, reports, i, "qtyq");

        ws4.addCell(times3_i);
        ws4.addCell(tenant_name3_i);
        ws4.addCell(user_name3_i);
        ws4.addCell(coun_counts_i);
        ws4.addCell(fsy_i);
        ws4.addCell(xxy_i);
        ws4.addCell(rztj_i);
        ws4.addCell(xltj_i);
        ws4.addCell(qtyq_i);

        if (i == reports.size() - 1) {
            int coun_counts_t = 0;
            int fsy_t = 0;
            int xxy_t = 0;
            int rztj_t = 0;
            int xltj_t = 0;
            int qtyq_t = 0;
            for (int j = 0; j < reports.size(); j++) {
                coun_counts_t += getCount(reports, j, "coun_counts");
                fsy_t += getCount(reports, j, "fsy");
                xxy_t += getCount(reports, j, "xxy");
                rztj_t += getCount(reports, j, "rztj");
                xltj_t += getCount(reports, j, "xltj");
                qtyq_t += getCount(reports, j, "qtyq");
            }
            Label times0_i_t = getData(0, reports, i + 1, "times", "合计");
            Label coun_counts_i_t = getData(3, reports, i + 1, "coun_counts", coun_counts_t + "");
            Label cmx_i_t = getData(4, reports, i + 1, "fsy", fsy_t + "");
            Label csp_i_t = getData(5, reports, i + 1, "xxy", xxy_t + "");
            Label cyy_i_t = getData(6, reports, i + 1, "rztj", rztj_t + "");
            Label cwz_i_t = getData(7, reports, i + 1, "xltj", xltj_t + "");
            Label cqt_i_t = getData(8, reports, i + 1, "qtyq", qtyq_t + "");

            ws4.addCell(times0_i_t);
            ws4.addCell(coun_counts_i_t);
            ws4.addCell(cmx_i_t);
            ws4.addCell(csp_i_t);
            ws4.addCell(cyy_i_t);
            ws4.addCell(cwz_i_t);
            ws4.addCell(cqt_i_t);
        }
    }

    private void paintingForCC4(WritableSheet ws4) throws WriteException, RowsExceededException {
        Label times3 = new Label(0, 0, "日期");
        Label tenant_name3 = new Label(1, 0, "学校名称");
        Label user_name3 = new Label(2, 0, "专业人员名称");
        Label coun_counts = new Label(3, 0, "咨询次数");
        Label fsy = new Label(4, 0, "放松椅");
        Label xxy = new Label(5, 0, "宣泄仪");
        Label rztj = new Label(6, 0, "认知调节仪器");
        Label xltj = new Label(7, 0, "积极心理调节仪器");
        Label qtyq = new Label(8, 0, "其他仪器");

        ws4.addCell(times3);
        ws4.addCell(tenant_name3);
        ws4.addCell(user_name3);
        ws4.addCell(coun_counts);
        ws4.addCell(fsy);
        ws4.addCell(xxy);
        ws4.addCell(rztj);
        ws4.addCell(xltj);
        ws4.addCell(qtyq);
    }

    private void paintingForCC3(WritableSheet ws3) throws WriteException, RowsExceededException {
        Label times3 = new Label(0, 0, "日期");
        Label tenant_name3 = new Label(1, 0, "学校名称");
        Label user_name3 = new Label(2, 0, "专业人员名称");
        Label coun_counts = new Label(3, 0, "咨询次数");
        Label cmx = new Label(4, 0, "面询");
        Label csp = new Label(5, 0, "视频咨询（包括微信视频、QQ视频等）");
        Label cyy = new Label(6, 0, "语音咨询（包括电话、微信语音、QQ语音等)");
        Label cwz = new Label(7, 0, "文字咨询（包括短信、邮箱、微信文字、QQ文字、书信咨询等）");
        Label cqt = new Label(8, 0, "其他");

        ws3.addCell(times3);
        ws3.addCell(tenant_name3);
        ws3.addCell(user_name3);
        ws3.addCell(coun_counts);
        ws3.addCell(cmx);
        ws3.addCell(csp);
        ws3.addCell(cyy);
        ws3.addCell(cwz);
        ws3.addCell(cqt);
    }

    private void paintingForCC2(WritableSheet ws2) throws WriteException, RowsExceededException {
        Label times2 = new Label(0, 0, "日期");
        Label tenant_name2 = new Label(1, 0, "学校名称");
        Label user_name2 = new Label(2, 0, "专业人员名称");
        Label case_counts2 = new Label(3, 0, "咨询总数");
        Label identity_xs = new Label(4, 0, "学生");
        Label identity_fm = new Label(5, 0, "父母");
        Label identity_ls = new Label(6, 0, "老师");
        Label identity_qt = new Label(7, 0, "其他");

        ws2.addCell(times2);
        ws2.addCell(tenant_name2);
        ws2.addCell(user_name2);
        ws2.addCell(case_counts2);
        ws2.addCell(identity_xs);
        ws2.addCell(identity_fm);
        ws2.addCell(identity_ls);
        ws2.addCell(identity_qt);
    }

    private void paintingForCC1(WritableSheet ws2) throws WriteException, RowsExceededException {
        Label times2 = new Label(0, 0, "日期");
        Label tenant_name2 = new Label(1, 0, "学校名称");
        Label user_name2 = new Label(2, 0, "专业人员名称");
        Label case_counts2 = new Label(3, 0, "个案总数");
        Label man = new Label(4, 0, "男生");
        Label women = new Label(5, 0, "女生");
        Label xx = new Label(6, 0, "小学");
        Label cz = new Label(7, 0, "初中");
        Label gz = new Label(8, 0, "高中");
        Label yey = new Label(9, 0, "幼儿园等");
        Label university = new Label(10, 0, "高校");
        Label teenager = new Label(11, 0, "青少年");
        Label middleage = new Label(12, 0, "中年");
        Label oldage = new Label(13, 0, "老年");

        ws2.addCell(times2);
        ws2.addCell(tenant_name2);
        ws2.addCell(user_name2);
        ws2.addCell(case_counts2);
        ws2.addCell(man);
        ws2.addCell(women);
        ws2.addCell(xx);
        ws2.addCell(cz);
        ws2.addCell(gz);
        ws2.addCell(yey);
        ws2.addCell(university);
        ws2.addCell(teenager);
        ws2.addCell(middleage);
        ws2.addCell(oldage);
    }

    private void paintingForCC(WritableSheet ws) throws WriteException, RowsExceededException {
        Label times = new Label(0, 0, "日期");
        Label tenant_name = new Label(1, 0, "学校名称");
        Label user_name = new Label(2, 0, "专业人员名称");
        Label case_counts = new Label(3, 0, "个案总数");
        Label yqyq = new Label(4, 0, "因疫情引起的心理援助");
        Label xywt = new Label(5, 0, "学业问题");
        Label ywwt = new Label(6, 0, "行为问题");
        Label qxet = new Label(7, 0, "情绪问题");
        Label jsjb = new Label(8, 0, "精神类疾病及转介");
        Label qcq = new Label(9, 0, "青春期心理问题");
        Label tbjw = new Label(10, 0, "同伴交往问题");
        Label ssgx = new Label(11, 0, "师生关系问题");
        Label sjwl = new Label(12, 0, "手机与网络依赖");
        Label sxzx = new Label(13, 0, "升学与择学、择业问题");
        Label jthj = new Label(14, 0, "家庭环境不利");
        Label qzgx = new Label(15, 0, "亲子关系问题");
        Label xlwj = new Label(16, 0, "心理危机");
        Label hf = new Label(17, 0, "回访");
        Label qt = new Label(18, 0, "其他");

        ws.addCell(times);
        ws.addCell(tenant_name);
        ws.addCell(user_name);
        ws.addCell(case_counts);
        ws.addCell(yqyq);
        ws.addCell(xywt);
        ws.addCell(ywwt);
        ws.addCell(qxet);
        ws.addCell(jsjb);
        ws.addCell(qcq);
        ws.addCell(tbjw);
        ws.addCell(ssgx);
        ws.addCell(sjwl);
        ws.addCell(sxzx);
        ws.addCell(jthj);
        ws.addCell(qzgx);
        ws.addCell(xlwj);
        ws.addCell(hf);
        ws.addCell(qt);
    }

    private static Label getData(int tableNum, List<Map<String, Object>> reports, int i, String name, String timeStr) {
        Label whole_name_i = new Label(tableNum, i + 1, timeStr);
        return whole_name_i;
    }

    private static Label getData(int tableNum, List<Map<String, Object>> reports, int i, String name) {
        Label whole_name_i;

        if (reports.get(i).get(name) != null && !reports.get(i).get(name).toString().equals("")) {
            whole_name_i = new Label(tableNum, i + 1,
                    !reports.get(i).get(name).toString().isEmpty() ? reports.get(i).get(name).toString() : "0");
        } else {
            whole_name_i = new Label(tableNum, i + 1, "0");
        }
        return whole_name_i;
    }

    private static int getCount(List<Map<String, Object>> reports, int i, String name) {
        int count = 0;

        if (reports.get(i).get(name) != null && !reports.get(i).get(name).toString().equals("")) {
            count = reports.get(i).get(name).toString().isEmpty() ? 0
                    : Integer.valueOf(reports.get(i).get(name).toString());
        } else {
            return 0;
        }
        return count;
    }

    /**
     * 新增专家补充信息
     */
    @RequestMapping("/updateExtPsychologist")
    @ResponseBody
    public ResponseData updateExtPsychologist(ExtPsychologist psychologist) {
        log.info("==================专家补充信息更新==================");
        ResponseData reData = new ResponseData();
        try {
            int count = extPsychologistService.insertSelective(psychologist);
            reData.setMsg("专家补充信息成功!");
        } catch (Exception e) {
            e.printStackTrace();
            reData.setCode(-1);
            reData.setMsg("专家补充信息失败!");
        }
        return reData;
    }

    /**
     * 获取普通用户所在单位及以上咨询师列表
     *
     * @param user_uuid 用户id
     * @return
     */
    @RequestMapping(value = "/getPsyInfoListForMB")
    @ResponseBody
    public ResponseData getPsyInfoListForMB(String user_uuid, String psy_name) {
        Map<String, Object> map = new HashMap<String, Object>();
        ResponseData mResponseData = new ResponseData();
        EUser operator = getUserInfoByUuid(user_uuid);
        List<Long> framework_ids = new ArrayList<>();
        if (operator.getFramework_id() != null) {
            List<Long> allTenantFrameworksId = getAllFathersTenantFrameworksId(operator.getFramework_id());
            framework_ids.add(operator.getFramework_id());
            if (allTenantFrameworksId != null)
                framework_ids.addAll(allTenantFrameworksId);
            map.put("framework_ids", framework_ids);
        }
        if (psy_name != null && !"".equals(psy_name))
            map.put("real_name", psy_name);
        map.put("user_type", 2);

        List<AdminUser> list = adminUserService.listAllAdminUsersByMap(map);
        for (int i = 0; i < list.size(); i++) {
            ExtPsychologist psy = new ExtPsychologist();
            psy = extPsychologistService.selectExtPsyInfoByUserUuid(list.get(i).getUuid());
            if (psy != null) {
                list.get(i).setGood_at(psy.getGood_at());
            } else {
                list.get(i).setGood_at("未设置");
            }
            if (list.get(i).getUuid() == operator.getUuid()) {
                AdminUser usertemp = new AdminUser();
                usertemp = list.get(0);
                list.set(0, list.get(i));
                list.set(i, usertemp);
            }
        }
        map.clear();
        map.put("list", list);
        mResponseData.setData(map);
        return mResponseData;
    }

    /**
     * 普通用户预约
     *
     * @param request
     * @param orderdate 日期
     * @param ordertime 时间段
     * @param user_uuid 用户
     * @param psyid     咨询师
     * @param status    默认0
     * @return
     */
    @RequestMapping(value = "/addCustomOrderForMB", method = RequestMethod.POST)
    @ResponseBody
    public ResponseData addCustomOrderForMB(HttpServletRequest request, String orderdate, String ordertime, String user_uuid,
                                            String psyid, Integer status, String remark,String isAdd) {
        TenantOrderInfo orderinfo = new TenantOrderInfo();
        ResponseData mResponseData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        Integer flagalter = 1;// 默认可以修改
        EUser user = getUserInfoByUuid(user_uuid);
        if (status == null)
            status = 0;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        orderinfo.setOrder_time(ordertime);
        orderinfo.setUser_uuid(user_uuid);
        orderinfo.setPsychologist_id(psyid);
        orderinfo.setStatus(status);
        orderinfo.setRemark(remark);
        String time = DateTimeUtil.getNowString();
        orderinfo.setCreate_date(DateTimeUtil.getUtcFromStrings(time));

        try {
            map.put("psychologist_id", psyid);
            map.put("order_date", DateTimeUtil.getUtcFromStrings(orderdate + " 00:00:00") / 1000);
            map.put("order_time", ordertime);
            map.put("valid_status", "1");
            List<TenantOrderInfo> orderInfoList = new ArrayList<>();
            if (StringUtils.isEmpty(isAdd)) {
                orderInfoList = tenantOrderInfoService.listAllOrderInfos(null, map);
                if (orderInfoList.size() > 0) {
                    flagalter = 3;
                    for (TenantOrderInfo tenantOrderInfo:orderInfoList) {
                        if (user_uuid.equals(tenantOrderInfo.getUser_uuid())) {
                            flagalter = 2;
                            break;
                        }
                    }
                }
            } else {
                map.put("user_uuid", user_uuid);
                orderInfoList = tenantOrderInfoService.listAllOrderInfos(null, map);
                if (orderInfoList.size() > 0) {
                    flagalter = 2;
                }
            }

            if (flagalter == 1) {
                Date orderdatenew = format.parse(orderdate);
                orderinfo.setOrder_date(orderdatenew.getTime() / 1000);
                tenantOrderInfoService.insert(orderinfo);
                mResponseData.setMsg("预约成功！");
                TenantNotices notice = new TenantNotices();
                String content = "您有预约信息：" + user.getReal_name() + "在" + DateTimeUtil.getNowString() + "发送预约申请！请及时查看和审批预约信息。";
                notice.setUser_uuid(psyid);
                notice.setContent(content);
                notice.setReaded(0);
                tenantNoticesService.insert(notice);

                sendEmailRemind(psyid,"预约成功提醒",content);
                // 预约咨询增量推送
                pushStatAppiont(user.getChannel_id(), user.getFramework_id());
            } else if (flagalter == 2){
                mResponseData.setCode(-1);
                mResponseData.setMsg("该咨询师该段时间你已经预约过了！");
            } else {
                mResponseData.setCode(-2);
                mResponseData.setMsg("该咨询师该段时间已经被预约了,是否依然预约该时段！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            mResponseData.setCode(-1);
            mResponseData.setMsg("预约失败！");
        }
        return mResponseData;
    }

    /**
     * 咨询师预约普通用户
     *
     * @param request
     * @param orderdate  日期
     * @param ordertime  时间段
     * @param user_uuids 用户
     * @param psyid      咨询师
     * @return
     */
    @RequestMapping(value = "/psyAddCustomOrder", method = RequestMethod.POST)
    @ResponseBody
    public ResponseData psyAddCustomOrder(HttpServletRequest request, String orderdate, String ordertime, String user_uuids,
                                          String psyid, String remark) {
        TenantOrderInfo orderinfo = new TenantOrderInfo();
        ResponseData mResponseData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            AdminUser adminUser = getAdminUserInfoByUuid(psyid);
            String[] usrUuidArr = user_uuids.split(",");
            for (String useruuid : usrUuidArr) {
                EUser user = getUserInfoByUuid(useruuid);
                map.put("user_uuid", useruuid);
                map.put("psychologist_id", psyid);
                map.put("order_date", DateTimeUtil.getUtcFromStrings(orderdate + " 00:00:00") / 1000);
                map.put("order_time", ordertime);
                map.put("valid_status", "1");
                List<TenantOrderInfo> orderInfoList = tenantOrderInfoService.listAllOrderInfos(null, map);
                Boolean isExits = false;
                for (TenantOrderInfo orderInfo:orderInfoList) {
                    if (orderInfo.getStatus() == 0) {
                        orderInfo.setStatus(1);
                        tenantOrderInfoService.updateByPrimaryKeySelective(orderInfo);
                        TenantNotices notice = new TenantNotices();
                        notice.setUser_uuid(useruuid);
                        notice.setContent(
                                "您有预约信息：" + adminUser.getReal_name() + "在" + DateTimeUtil.getNowString() + "预约了"+user.getReal_name()+"！请及时查看。");
                        notice.setReaded(0);
                        tenantNoticesService.insert(notice);
                        isExits = true;
                    } else if (orderInfo.getStatus() == 1) {
                        isExits = true;
                    }
                }

                if (!isExits) {
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    orderinfo.setOrder_time(ordertime);
                    orderinfo.setUser_uuid(useruuid);
                    orderinfo.setPsychologist_id(psyid);
                    orderinfo.setStatus(1);
                    orderinfo.setRemark(remark);
                    String time = DateTimeUtil.getNowString();
                    orderinfo.setCreate_date(DateTimeUtil.getUtcFromStrings(time));
                    Date orderdatenew = format.parse(orderdate);
                    orderinfo.setOrder_date(orderdatenew.getTime() / 1000);
                    tenantOrderInfoService.insert(orderinfo);

                    TenantNotices notice = new TenantNotices();
                    notice.setUser_uuid(useruuid);
                    notice.setContent(
                            "您有预约信息：" + adminUser.getReal_name() + "在" + DateTimeUtil.getNowString() + "预约了"+user.getReal_name()+"！请及时查看。");
                    notice.setReaded(0);
                    tenantNoticesService.insert(notice);
                }
            }
            if (usrUuidArr.length == 0) {
                mResponseData.setCode(-1);
                mResponseData.setMsg("请选择要预约的用户！");
            } else {
                mResponseData.setMsg("预约成功！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            mResponseData.setCode(-1);
            mResponseData.setMsg("预约失败！");
        }

        return mResponseData;
    }

    /**
     * 获取用户的所有预约
     *
     * @param psyid
     * @param user_uuid
     * @return
     */
    @RequestMapping("/selectOrderInfoByAdminUserForMB")
    @ResponseBody
    public ResponseData selectOrderInfoByAdminUserForMB(String psyid, String user_uuid) {
        Map<String, Object> map = new HashMap<String, Object>();
        ResponseData mResponseData = new ResponseData();
        map.put("psychologist_id", psyid);
        map.put("user_uuid", user_uuid);
        List<TenantOrderInfo> OrderInfoList = tenantOrderInfoService.listAllOrderInfos(null, map);
        map.clear();
        map.put("OrderInfoList", OrderInfoList);
        mResponseData.setData(map);
        return mResponseData;
    }

    /**
     * 普通用户预约取消预约
     *
     * @param request
     * @param orderid
     * @return
     */
    @RequestMapping(value = "/cancelCustomOrderForMB", method = RequestMethod.POST)
    @ResponseBody
    public ResponseData cancelCustomOrderForMB(HttpServletRequest request, Long orderid) {
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        ResponseData mResponseData = new ResponseData();

        try {
            TenantOrderInfo mOrderInfo = tenantOrderInfoService.selectByPrimaryKey(orderid);
            // 将之前的预约信息取消掉
            mOrderInfo.setStatus(4);
            tenantOrderInfoService.updateByPrimaryKeySelective(mOrderInfo);

            mResponseData.setMsg("取消预约成功！");
            String userUuid = mOrderInfo.getUser_uuid();
            String psyid = mOrderInfo.getPsychologist_id();
            Map<String, Object> map = new HashMap<String, Object>();
            EUser user = getUserInfoByUuid(userUuid);
            TenantNotices notice = new TenantNotices();
            notice.setUser_uuid(psyid);
            String content = "您有预约信息：" + user.getReal_name() + "在" + DateTimeUtil.getNowString() + "取消了预约！请知晓。";
            notice.setContent(content);
            notice.setReaded(0);
            tenantNoticesService.insert(notice);

            sendEmailRemind(psyid,"取消预约提醒",content);
        } catch (Exception e) {
            e.printStackTrace();
            // log.debug(e.getMessage());
            mResponseData.setCode(-1);
            mResponseData.setMsg("预约取消失败！");
        }
        return mResponseData;
    }

    /**
     * 咨询师 获取自己的所有预约
     *
     * @param psyid
     * @return
     */
    @RequestMapping("/selectOrderInfoByAdminForMB")
    @ResponseBody
    public ResponseData selectOrderInfoByAdminForMB(String psyid) {
        Map<String, Object> map = new HashMap<String, Object>();
        ResponseData mResponseData = new ResponseData();
        map.put("psychologist_id", psyid);
        List<TenantOrderInfo> OrderInfoList = tenantOrderInfoService.listAllOrderInfos(null, map);
        map.clear();
        map.put("OrderInfoList", OrderInfoList);
        mResponseData.setData(map);
        return mResponseData;
    }

    /**
     * 根据预约id 获取详细信息
     *
     * @param orderid
     * @return
     */
    @RequestMapping("/orderDetailInfoForMB")
    @ResponseBody
    public ResponseData orderDetailInfoForMB(Long orderid) {
        ResponseData mResponseData = new ResponseData();
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        Map<String, Object> map = new HashMap<String, Object>();
        PageInfo pi = new PageInfo();
        TenantOrderInfo mOrderInfo = tenantOrderInfoService.selectByPrimaryKey(orderid);
        try {
            Map<String, Object> maptemp = new HashMap<String, Object>();
            EUser usertemp = getUserInfoByUuid(mOrderInfo.getUser_uuid());
            mOrderInfo.setUserReal_name(usertemp.getReal_name());
            mOrderInfo.setUser_gender(usertemp.getUser_gender());
            Map<String, Object> p_maps = new HashMap<String, Object>();
            p_maps.put("id", usertemp.getFramework_id());
            long frameworkid = usertemp.getFramework_id();
            TenantFrameworks framework = tenantFrameworksService.getFrameworkById(frameworkid);
            if (framework != null) {
                mOrderInfo.setWhole_name(framework.getWhole_name());
            }
            AdminUser usertempPsy = getAdminUserInfoByUuid(mOrderInfo.getPsychologist_id());
            mOrderInfo.setPsychologist_name(usertempPsy.getReal_name());
        } catch (Exception e) {
            e.printStackTrace();
        }
        map.put("mOrderInfo", mOrderInfo);
        mResponseData.setData(map);
        return mResponseData;
    }

    /**
     * 咨询师审批预约
     *
     * @param request
     * @param orderid
     * @param status
     * @return
     */
    @RequestMapping(value = "/updateOrderForMB", method = RequestMethod.POST)
    @ResponseBody
    public ResponseData updateOrderForMB(HttpServletRequest request, Long orderid, int status, @RequestParam(required = true) String admin_uuid) {
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        ResponseData mResponseData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        AdminUser user = getAdminUserInfoByUuid(admin_uuid);
        try {
            TenantOrderInfo mOrderInfo = tenantOrderInfoService.selectByPrimaryKey(orderid);
            // 将之前的预约信息取消掉
            mOrderInfo.setStatus(status);
            tenantOrderInfoService.updateByPrimaryKeySelective(mOrderInfo);
            map.put("bool", true);
            map.put("msg", "预约审批成功");
            TenantNotices notice = new TenantNotices();
            notice.setUser_uuid(mOrderInfo.getUser_uuid());
            if (status == 1) {
                notice.setContent("你有预约信息：在" + DateTimeUtil.getNowString() + "老师审批通过！请按时去咨询，谢谢！");
            } else {
                notice.setContent("你有预约信息：在" + DateTimeUtil.getNowString() + "老师审批没有通过！");
            }
            notice.setReaded(0);
            tenantNoticesService.insert(notice);

        } catch (Exception e) {
            e.printStackTrace();
            map.put("bool", false);
            map.put("msg", "预约审批失败");
        }
        mResponseData.setData(map);
        return mResponseData;
    }

    /**
     * @param request
     * @param examplelimit 周几 如:1,2,3,4,5 默认时间下开放预约的日期
     * @param admin_uuid   咨询师的id
     * @param is_scustom   0为默认 1 为自定义时间
     * @param mon_times
     * @param tue_times
     * @param wed_times
     * @param thu_times
     * @param fri_times
     * @param sat_times
     * @param sun_times
     * @param open_week2   周几 如:1,2,3,4,5 自定义时间下开放预约的日期
     * @return
     */
    @RequestMapping(value = "/addOrderDateForMB")
    @ResponseBody
    public ResponseData addOrderDateForMB(HttpServletRequest request, String examplelimit, @RequestParam(required = true) String admin_uuid,
                                          Integer is_scustom, String mon_times, String tue_times, String wed_times, String thu_times,
                                          String fri_times, String sat_times, String sun_times, String open_week2) {
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());

        ResponseData mResponseData = new ResponseData();
        if (is_scustom == null) {
            is_scustom = 0;
        }
        if (is_scustom == 1 && (open_week2 == null || "".equals(open_week2))) {
            mResponseData.setCode(-1);
            mResponseData.setMsg("自定时时间不能为空");
            return mResponseData;
        }
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            AdminUser user = getAdminUserInfoByUuid(admin_uuid);
            List<TenantOrderPsychologist> psychologist = new ArrayList<TenantOrderPsychologist>();
            psychologist = tenantOrderPsychologistService.listPsychologistsbyPsyid(admin_uuid);
            if (psychologist.size() > 0) {
                psychologist.get(0).setOpen_week(examplelimit);
                psychologist.get(0).setPsychologist_id(admin_uuid);
                psychologist.get(0).setFramework_id(user.getFramework_id());
                psychologist.get(0).setChannel_id(user.getChannel_id());
                psychologist.get(0).setEnabled(1);
                psychologist.get(0).setIs_scustom(is_scustom);
                psychologist.get(0).setOpen_week2(open_week2);
                if (mon_times != null && !"".equals(mon_times))
                    psychologist.get(0).setMon_times(mon_times);
                if (tue_times != null && !"".equals(tue_times))
                    psychologist.get(0).setTue_times(tue_times);
                if (wed_times != null && !"".equals(wed_times))
                    psychologist.get(0).setWed_times(wed_times);
                if (thu_times != null && !"".equals(thu_times))
                    psychologist.get(0).setThu_times(thu_times);
                if (fri_times != null && !"".equals(fri_times))
                    psychologist.get(0).setFri_times(fri_times);
                if (sat_times != null && !"".equals(sat_times))
                    psychologist.get(0).setSat_times(sat_times);
                if (sun_times != null && !"".equals(sun_times))
                    psychologist.get(0).setSun_times(sun_times);
                tenantOrderPsychologistService.updateByPrimaryKeySelective(psychologist.get(0));
                mResponseData.setMsg("预约日期设置成功！");

            } else {
                TenantOrderPsychologist psychologistlist = new TenantOrderPsychologist();
                psychologistlist.setOpen_week(examplelimit);
                psychologistlist.setPsychologist_id(admin_uuid);
                psychologistlist.setChannel_id(user.getChannel_id());
                psychologistlist.setFramework_id(user.getFramework_id());
                psychologistlist.setEnabled(1);
                psychologistlist.setIs_scustom(is_scustom);
                psychologistlist.setOpen_week2(open_week2);
                if (mon_times != null && !"".equals(mon_times))
                    psychologistlist.setMon_times(mon_times);
                if (tue_times != null && !"".equals(tue_times))
                    psychologistlist.setTue_times(tue_times);
                if (wed_times != null && !"".equals(wed_times))
                    psychologistlist.setWed_times(wed_times);
                if (thu_times != null && !"".equals(thu_times))
                    psychologistlist.setThu_times(thu_times);
                if (fri_times != null && !"".equals(fri_times))
                    psychologistlist.setFri_times(fri_times);
                if (sat_times != null && !"".equals(sat_times))
                    psychologistlist.setSat_times(sat_times);
                if (sun_times != null && !"".equals(sun_times))
                    psychologistlist.setSun_times(sun_times);
                tenantOrderPsychologistService.insertSelective(psychologistlist);
                mResponseData.setMsg("预约日期更新成功！");

            }
        } catch (Exception e) {
            e.printStackTrace();
            mResponseData.setCode(-1);
            mResponseData.setMsg("新增失败");
        }

        return mResponseData;
    }

    /**
     * 更新排班时间
     */
    @RequestMapping(value = "/updatePsychologistDateForMB", method = RequestMethod.POST)
    @ResponseBody
    public ResponseData updatePsychologistDateForMB(HttpServletRequest request, String examplelimit, @RequestParam(required = true) String admin_uuid,
                                                    Integer is_scustom, String mon_times, String tue_times, String wed_times, String thu_times,
                                                    String fri_times, String sat_times, String sun_times, String open_week2) {
        String opTime = new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date());
        ResponseData mResponseData = new ResponseData();
        if (is_scustom == null) {
            is_scustom = 0;
        }
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            AdminUser user = getAdminUserInfoByUuid(admin_uuid);
            TenantOrderPsychologist tenantOrderPsychologist = tenantOrderPsychologistService.getPsychologistsbyPsyid(admin_uuid);
            if (tenantOrderPsychologist != null) {
                TenantOrderPsychologist psychologist = new TenantOrderPsychologist();
                psychologist.setId(tenantOrderPsychologist.getId());
                psychologist.setOpen_week(examplelimit + "");
                psychologist.setPsychologist_id(admin_uuid);
                psychologist.setChannel_id(user.getChannel_id());
                psychologist.setEnabled(1);
                psychologist.setIs_scustom(is_scustom);
                psychologist.setOpen_week2(open_week2);
                if (mon_times != null && !"".equals(mon_times))
                    psychologist.setMon_times(mon_times);
                if (tue_times != null && !"".equals(tue_times))
                    psychologist.setTue_times(tue_times);
                if (wed_times != null && !"".equals(wed_times))
                    psychologist.setWed_times(wed_times);
                if (thu_times != null && !"".equals(thu_times))
                    psychologist.setThu_times(thu_times);
                if (fri_times != null && !"".equals(fri_times))
                    psychologist.setFri_times(fri_times);
                if (sat_times != null && !"".equals(sat_times))
                    psychologist.setSat_times(sat_times);
                if (sun_times != null && !"".equals(sun_times))
                    psychologist.setSun_times(sun_times);
                tenantOrderPsychologistService.updateByPrimaryKeySelective(psychologist);
                mResponseData.setMsg("预约时间设置成功！");

            } else {
                mResponseData.setCode(-1);
                mResponseData.setMsg("修改失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            mResponseData.setCode(-1);
            mResponseData.setMsg("修改失败");
        }

        return mResponseData;
    }

    /**
     * 咨询师预约编辑
     */
    @RequestMapping(value = "/psyEditCustomOrder", method = RequestMethod.POST)
    @ResponseBody
    public ResponseData psyEditCustomOrder(HttpServletRequest request, String orderdate, String ordertime, String user_uuid,
                                           String psyid, Long orderid) {
        TenantOrderInfo orderinfo = new TenantOrderInfo();
        ResponseData responseData = new ResponseData();
        AdminUser usertempPsy = getAdminUserInfoByUuid(psyid);
        EUser user = getUserInfoByUuid(user_uuid);
        Integer flagalter = 1;// 默认可以修改

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        orderinfo.setOrder_time(ordertime);
        orderinfo.setUser_uuid(user_uuid);
        orderinfo.setPsychologist_id(psyid);
        orderinfo.setStatus(1);

        String time = DateTimeUtil.getNowString();
        orderinfo.setCreate_date(DateTimeUtil.getUtcFromStrings(time));

        try {
            Map<String, Object> map = new HashMap<String, Object>();
            String dateweek = DateUtil.dateToWeek(orderdate);
            TenantOrderPsychologist psychologist = tenantOrderPsychologistService.getPsychologistsbyPsyid(psyid);
            if (psychologist != null) {
                int IsCustom = psychologist.getIs_scustom();
                if (IsCustom == 1) {
                    if (psychologist.getOpen_week2().indexOf(dateweek) == -1) {
                        // 不能修改
                        flagalter = 0;
                    }
                }
                map.put("user_uuid", user_uuid);
                map.put("psychologist_id", psyid);
                map.put("order_date", DateTimeUtil.getUtcFromStrings(orderdate + " 00:00:00") / 1000);
                map.put("order_time", ordertime);
                map.put("valid_status", "1");
                List<TenantOrderInfo> orderInfoList = tenantOrderInfoService.listAllOrderInfos(null, map);
                for (TenantOrderInfo orderInfo:orderInfoList) {
                    if (orderInfo.getStatus() == 0) {
                        flagalter = 2;
                    } else if (orderInfo.getStatus() == 1) {
                        flagalter = 3;
                    }
                }
            } else {
                // 不能修改
                flagalter = 0;
            }

            if (flagalter == 1) {
                Date orderdatenew = format.parse(orderdate);
                orderinfo.setOrder_date(orderdatenew.getTime() / 1000);
                orderinfo.setId(orderid);
                tenantOrderInfoService.updateByPrimaryKeySelective(orderinfo);

                TenantNotices notice = new TenantNotices();
                notice.setUser_uuid(user_uuid);
                notice.setContent("您有预约信息：" + usertempPsy.getReal_name() + "在" + DateTimeUtil.getNowString() + "修改了申请！请及时查看预约信息。");
                notice.setReaded(0);
                tenantNoticesService.insert(notice);
                responseData.setMsg("预约修改成功！");
            } else if (flagalter == 2) {
                responseData.setCode(-1);
                responseData.setMsg("当前时间，该用户存在待确认的预约！");
            } else if (flagalter == 3) {
                responseData.setCode(-1);
                responseData.setMsg("当前时间，该用户已经预约了！");
            } else {
                responseData.setCode(-1);
                responseData.setMsg("当前时间不可约，请选择其他时间！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            responseData.setCode(-1);
            responseData.setMsg("预约修改失败！");
        }
        return responseData;
    }

    /**
     * 通过咨询师id和普通用户id获取caseid
     *
     * @param user_uuid
     * @param admin_uuid
     * @return
     */
    @RequestMapping("/getCaseId")
    @ResponseBody
    public ResponseData getCaseId(@RequestParam String user_uuid, @RequestParam(required = true) String admin_uuid) {
        ResponseData responseData = new ResponseData();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("psychologist_id", admin_uuid);
        map.put("user_uuid", user_uuid);
        try {
            List<Map<String, Object>> list = tenantPsychologicalCaseService.listPsychologicalCaseByMap(null, map);
            map.clear();
            if (list.size() > 0) {
                map.put("case_id", list.get(0).get("id"));
                map.put("counseling_onlyid", list.get(0).get("counseling_onlyid"));
            }
            responseData.setData(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return responseData;
    }

    private void sendEmailRemind(String psyid,String subject,String content) {
        try {
            Map<String,Object> map = adminUserService.getPsyInfoByUuid(psyid);
            if (!StringUtils.isEmpty(map.get("email"))) {
                String toEmail = map.get("email").toString();
                String realName = map.get("real_name").toString();
                //MailUtil.sendEmail(toEmail,subject,realName+"你好,"+content);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 专家取消预约
     * @param orderid
     * @return
     */
    @RequestMapping(value = "/psyCancelCustomOrder", method = RequestMethod.POST)
    @ResponseBody
    public ResponseData psyCancelCustomOrder(@RequestParam Long orderid) {
        ResponseData responseData = new ResponseData();
        try {
            TenantOrderInfo mOrderInfo = tenantOrderInfoService.selectByPrimaryKey(orderid);
            mOrderInfo.setStatus(4);
            tenantOrderInfoService.updateByPrimaryKeySelective(mOrderInfo);
            String userUuid = mOrderInfo.getUser_uuid();
            String psyid = mOrderInfo.getPsychologist_id();
            EUser user = getUserInfoByUuid(userUuid);
            AdminUser usertempPsy = getAdminUserInfoByUuid(psyid);

            TenantNotices notice = new TenantNotices();
            notice.setUser_uuid(psyid);
            String content = "您有预约信息：" + usertempPsy.getReal_name() + "在" + DateTimeUtil.getNowString() + "取消了预约！请知晓。";
            notice.setContent(content);
            notice.setReaded(0);
            tenantNoticesService.insert(notice);

            String operation = usertempPsy.getUser_name()  + "取消了" + user.getUser_name() + "的预约";
            TenantLogs tenantLogs = new TenantLogs();
            tenantLogs.setUser_uuid(usertempPsy.getUuid());
            tenantLogs.setChannel_id(usertempPsy.getChannel_id());
            tenantLogs.setFramework_id(usertempPsy.getFramework_id());
            tenantLogs.setModule("order");
            tenantLogs.setOperation(operation);
            tenantLogsService.insert(tenantLogs);
            responseData.setMsg("取消预约成功！");
        } catch (Exception e) {
            e.printStackTrace();
            responseData.setCode(-1);
            responseData.setMsg("预约取消失败！");
        }
        return responseData;
    }

}